|
-
Sep 14th, 2003, 09:14 AM
#1
Thread Starter
Fanatic Member
While looping, skip current item if it meets a certain condition
I am looping through a collection of files, putting in the filesize as I go. However, I have a delimiter that changes to the previous directory in the path (EX: It will change to C:\Dir1 if I'm in C:\Dir1\Dir2.)
The problem is that it will also include that in the loop, since it's also a list item. I need to do something like this:
If the current item in the loop is my delimiter string (in this case ".."), then skip the item.
-
Sep 14th, 2003, 10:31 AM
#2
Just use an If statement
VB Code:
Do While <whatever>
If FileName <> ".." Then
'Put processing code here
End if
'Increment loop counter
Loop
-
Sep 14th, 2003, 12:56 PM
#3
Thread Starter
Fanatic Member
That did it. Now I have another similar question.
Take a look at the following code snippets:
VB Code:
Private Function GetLocalDirList()
Dim lstItem As ListItem
If lvwDirListings.ListItems.Count <> 0 Then lvwDirListings.ListItems.Clear
If Not Dir1.Path = Left$(Drive1.Drive, 2) & "\" Then
lvwDirListings.ListItems.Add , , ".."
End If
For i = 0 To Dir1.ListCount - 1
lvwDirListings.ListItems.Add , , Mid$(Dir1.List(i), 4)
Next i
GetLocalFileList
End Function
Private Function GetLocalFileList()
Dim lstItem As ListItem
For i = 0 To File1.ListCount - 1
lvwDirListings.ListItems.Add , , File1.List(i)
Next i
For i = 1 To lvwDirListings.ListItems.Count
If Not GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory And Not lvwDirListings.ListItems(i) = ".." Then
lvwDirListings.ListItems(i).SubItems(1) = Format(FileLen(Dir1.Path & "\" & lvwDirListings.ListItems(i)), "###,###,###")
End If
If GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory And Not lvwDirListings.ListItems(i) = ".." Then
lvwDirListings.ListItems(i).SubItems(1) = "<Directory>"
End If
Next i
End Function
This works fine, as long as I'm in the root directory. However, if I'm in any higher level directory, it displays the directory i selected in the path.
To illustrate what I'm talking about, I shall use the following example:
Let's say I'm in my root directory, and the root dir has these directories branching off it:
Dir1
Dir2
Dir3
I'll use Dir2 in this example, and pretend that Dir2 has the following subdirs:
Subdir1
Subdir2
Now when I doubleclick Dir2, the listview displays the following:
Dir2\Subdir1
Dir2\Subdir2
I'm "Path not found" errors as a result, because Dir1.Path would be C:\Dir2. There's no such directory as C:\Dir2\Dir2\Subdir1. I know I use Mid$ to solve this problem (as I have in the past), but I'm not sure how to use it in this situation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|