dir is stopping loop

R

redtux

Hi I have the following code in a vba module

Dim Mydir As String
Dim Mydir1 As String
Dim Myname As String
'Debug.Print path
Mydir = Dir(path, vbDirectory)
Do While Mydir <> "" ' Start the loop.

If Mydir <> "." And Mydir <> ".." Then

' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(path & Mydir) And vbDirectory) = vbDirectory Then

If Left(Mydir, 3) = "200" Then
Debug.Print Mydir ' Display entry only if it
Mydir1 = path & Mydir & "\"
Myname = Dir(Mydir1) ' if this is commented out the loop runs
but not otherwise

End If
End If ' it represents a directory.
End If


Mydir = Dir ' Get next entry.

Loop

The idea is to loop through sub-dirs and then to get file name in each
sub-dir, however the loop fails as above

any ideas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top