Results 1 to 3 of 3

Thread: While looping, skip current item if it meets a certain condition

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    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.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Just use an If statement

    VB Code:
    1. Do While <whatever>
    2.  
    3.     If FileName <> ".." Then
    4.         'Put processing code here
    5.     End if
    6.     'Increment loop counter
    7. Loop

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    That did it. Now I have another similar question.

    Take a look at the following code snippets:

    VB Code:
    1. Private Function GetLocalDirList()
    2.     Dim lstItem As ListItem
    3.     If lvwDirListings.ListItems.Count <> 0 Then lvwDirListings.ListItems.Clear
    4.     If Not Dir1.Path = Left$(Drive1.Drive, 2) & "\" Then
    5.         lvwDirListings.ListItems.Add , , ".."
    6.     End If
    7.     For i = 0 To Dir1.ListCount - 1
    8.         lvwDirListings.ListItems.Add , , Mid$(Dir1.List(i), 4)
    9.     Next i
    10.     GetLocalFileList
    11. End Function
    12.  
    13. Private Function GetLocalFileList()
    14.     Dim lstItem As ListItem
    15.     For i = 0 To File1.ListCount - 1
    16.         lvwDirListings.ListItems.Add , , File1.List(i)
    17.     Next i
    18.     For i = 1 To lvwDirListings.ListItems.Count
    19.         If Not GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory And Not lvwDirListings.ListItems(i) = ".." Then
    20.             lvwDirListings.ListItems(i).SubItems(1) = Format(FileLen(Dir1.Path & "\" & lvwDirListings.ListItems(i)), "###,###,###")
    21.         End If
    22.         If GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory And Not lvwDirListings.ListItems(i) = ".." Then
    23.             lvwDirListings.ListItems(i).SubItems(1) = "<Directory>"
    24.         End If
    25.     Next i
    26. 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
  •  



Click Here to Expand Forum to Full Width