On Sep 16, 9:27 pm, "Mac Lingo" <M...@SV-CaliforniaGirl.Com> wrote:
> 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
|