Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dir does not work anymore 2

Status
Not open for further replies.

harmmeijer

Programmer
Mar 1, 2001
869
CN
Both in visual studio 6.0 and in access the dir("somepath", vbdirectory) does not work anymore.
It gives a bs value, see below:
? dir("c:\", vbDirectory)
FRUNLOG.TXT

Well FRUNLOG.TXT is not a directory, if I use another directory (like windows) it gives me files as well as directorys. I might as well leave the vbDirecstory out of the command.

What can I do to fix this and how can it be (it worked yesterdaty). Did I pick up something unpleasant from the net?
 
Hi harmmeijer,
This code is from the help file on "Dir"; I don't really understand Microsoft's logic in this, but I think maybe the "vbDirectory" flag tells Dir to include directories when it's returning strings, not to only include directories:

--- Begin Code ---
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
' Retrieve the first entry.
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> &quot;&quot; ' Start the loop.
' Ignore the current directory and the
' encompassing directory.

If MyName <> &quot;.&quot; And MyName <> &quot;..&quot; Then
' Use bitwise comparison to make sure
' MyName is a directory.

If (GetAttr(MyPath & MyName) And _
vbDirectory) = vbDirectory Then
' Display entry only if it
' represents a directory.

Debug.Print MyName
End If
End If
MyName = Dir ' Get next entry.
Loop
--- End Code ---


Hope that helps!
 
You are so correct, I think the following line was wrong in my code:
If (GetAttr(MyPath & MyName) And _
vbDirectory) = vbDirectory Then
I have got the same code from ms access help but changed it to get all the subdirs as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top