How can I access Directory Names?

M

Mac Lingo

I need to be able to get at Directory Names. The3 problem is that I want to
go thru my directories with a VBA program and would like, for instance, to
change directories within that program.

I know how to use "Dir" to get File Names, but it doesn't seem to display
Directory names.

Anyone know how?

Thanks,
Mac Lingo
 
L

Leith Ross

I need to be able to get at Directory Names. The3 problem is that I want to
go thru my directories with a VBA program and would like, for instance, to
change directories within that program.

I know how to use "Dir" to get File Names, but it doesn't seem to display
Directory names.

Anyone know how?

Thanks,
Mac Lingo

Hello Mac,

Straight from the VBA help files. This will start with a parent
directory that you choose, and lists all other directories in that
folder.

' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory
Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

Sincerely,
Leith Ross
 
G

Guest

Hi Mac,

I modified this from the help files. It gets your current path and lists the
directories in that path.

Sub Test_Dir_Path()
Dim MyPath As String
Dim myName As String

' Display the names that represent directories.
MyPath = CurDir & "\" ' Set the path and add "\"

MsgBox "Current path is:- " & Chr(13) & _
MyPath 'For testing purposes

' Retrieve the first entry.
myName = Dir(MyPath, vbDirectory)
Do While myName <> "" ' Start the loop.
' Ignore the current and encompassing directory.
If myName <> "." And myName <> ".." Then
' Test that is a directory
If (GetAttr(MyPath & myName) And vbDirectory) _
= vbDirectory Then
MsgBox myName 'For testing purposes
End If
End If
myName = Dir 'Get next entry.
Loop
End Sub

Regards,

OssieMac
 

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