R
Ray
The following code writes the contents (directories and files) into a text
file. It indents directories then places the filenames in line beneath that
directory. When it encounters another directory it indents again. The problem
I have is I do not know how to check if the directory is a SUB directory?
Onces the program hits a new parent directory I would like to reset the tab
to 0. The resulting print would be formatted like windows explorer listing
with subdirectories incrementally tabbed beneath its parent directory and all
parent directories to have no indentation.
Bottom line I need a method to check if property a subdirectory. Current
code shown below:
txtfile = "c:\temp\List2.txt"
Filenum = FreeFile
numfiles = 1
tabbed = 1
Open txtfile For Output Access Write As Filenum
' 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
tabbed = tabbed + 1
Print #Filenum, Tab(tabbed); "-->"; myname
Else
Print #Filenum, Tab(tabbed + 4); myname
End If ' it represents a directory.
End If
myname = Dir ' Get next entry.
Loop
Close #Filenum
file. It indents directories then places the filenames in line beneath that
directory. When it encounters another directory it indents again. The problem
I have is I do not know how to check if the directory is a SUB directory?
Onces the program hits a new parent directory I would like to reset the tab
to 0. The resulting print would be formatted like windows explorer listing
with subdirectories incrementally tabbed beneath its parent directory and all
parent directories to have no indentation.
Bottom line I need a method to check if property a subdirectory. Current
code shown below:
txtfile = "c:\temp\List2.txt"
Filenum = FreeFile
numfiles = 1
tabbed = 1
Open txtfile For Output Access Write As Filenum
' 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
tabbed = tabbed + 1
Print #Filenum, Tab(tabbed); "-->"; myname
Else
Print #Filenum, Tab(tabbed + 4); myname
End If ' it represents a directory.
End If
myname = Dir ' Get next entry.
Loop
Close #Filenum