Looping to list subdirectorys

Looping to list subdirectorys

Anonymous
Not applicable
177 Views
3 Replies
Message 1 of 4

Looping to list subdirectorys

Anonymous
Not applicable
Can anyone help me with this problem ??
I am looking for a method to list all files, or drawings in a directory
structure.
I have used the Dir function to return a list of files and folders in a
specified folder, but I need to be able to specify a starting point, then
have the Dir routine list every file and sub folder from that point on !
Am I right in thinking I need to look at putting a loop into this to read
down to the lowest directory first, and if so can you help out with this
please ?
Is it also possible to extract the file owner as well ??????

Many Thanks
Dave

P.S. This is code I am using..

Dim MyFile, MyPath, MyName, MyInfo As String, AllInfo

Open "c:\temp\filesListExp.txt" For Output As #1

' 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.
If (GetAttr(MyPath & MyName) And vbfile) = vbfile Then
MyInfo = FileDateTime(MyPath & MyName)
AllInfo = MyPath & MyName & "," & MyName & "," & MyInfo
Write #1, AllInfo ' Display entry only if it
End If ' it represents a directory.

End If
MyName = Dir ' Get next entry.
Loop
0 Likes
178 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Have you looked at the Microsoft Scripting Runtime component? It contains
the FileSystemObject which should be helpful when handling directories and
files.

--
Rune Wold
System Analyst
Engineering Systems
rune@engsys.no
--
0 Likes
Message 3 of 4

Anonymous
Not applicable
You can use the built in Windows API functions FindFirstFile,
FindNextFile, which will also populate the WIN32_FIND_DATA
structures for you. Once you've declared the APIs and made your
first call to FindFirstFile, recursively call FindNextFile to walk the
directory and any of its subdirectories. Your recursive function will
make decisions based on the populated values in WIN32_FIND_DATA.

This may sound difficult but it's really not, and it works all the way
back to Win 95.

Paul Kohut

"Dave Wilkinson" wrote in message
news:CDECD1F638FC2A1BB5243F3986F3DD58@in.WebX.maYIadrTaRb...
> Can anyone help me with this problem ??
> I am looking for a method to list all files, or drawings in a directory
> structure.
> I have used the Dir function to return a list of files and folders in a
> specified folder, but I need to be able to specify a starting point, then
> have the Dir routine list every file and sub folder from that point on !
> Am I right in thinking I need to look at putting a loop into this to read
> down to the lowest directory first, and if so can you help out with this
> please ?
> Is it also possible to extract the file owner as well ??????
>
> Many Thanks
> Dave
>
> P.S. This is code I am using..
>
> Dim MyFile, MyPath, MyName, MyInfo As String, AllInfo
>
> Open "c:\temp\filesListExp.txt" For Output As #1
>
> ' 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.
> If (GetAttr(MyPath & MyName) And vbfile) = vbfile Then
> MyInfo = FileDateTime(MyPath & MyName)
> AllInfo = MyPath & MyName & "," & MyName & "," & MyInfo
> Write #1, AllInfo ' Display entry only if it
> End If ' it represents a directory.
>
> End If
> MyName = Dir ' Get next entry.
> Loop
>
>
0 Likes
Message 4 of 4

Anonymous
Not applicable
PS, a quick look on www.codeguru.com/vb/index.shtml
under the files section provides sample source for
what I was talking about.

Paul Kohut


"Paul Kohut" wrote in message
news:954F6A48B408F6490250C55117F7F16F@in.WebX.maYIadrTaRb...
> You can use the built in Windows API functions FindFirstFile,
> FindNextFile, which will also populate the WIN32_FIND_DATA
> structures for you. Once you've declared the APIs and made your
> first call to FindFirstFile, recursively call FindNextFile to walk the
> directory and any of its subdirectories. Your recursive function will
> make decisions based on the populated values in WIN32_FIND_DATA.
>
> This may sound difficult but it's really not, and it works all the way
> back to Win 95.
>
> Paul Kohut
>
> "Dave Wilkinson" wrote in message
> news:CDECD1F638FC2A1BB5243F3986F3DD58@in.WebX.maYIadrTaRb...
> > Can anyone help me with this problem ??
> > I am looking for a method to list all files, or drawings in a directory
> > structure.
> > I have used the Dir function to return a list of files and folders in a
> > specified folder, but I need to be able to specify a starting point,
then
> > have the Dir routine list every file and sub folder from that point on !
> > Am I right in thinking I need to look at putting a loop into this to
read
> > down to the lowest directory first, and if so can you help out with this
> > please ?
> > Is it also possible to extract the file owner as well ??????
> >
> > Many Thanks
> > Dave
> >
> > P.S. This is code I am using..
> >
> > Dim MyFile, MyPath, MyName, MyInfo As String, AllInfo
> >
> > Open "c:\temp\filesListExp.txt" For Output As #1
> >
> > ' 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.
> > If (GetAttr(MyPath & MyName) And vbfile) = vbfile Then
> > MyInfo = FileDateTime(MyPath & MyName)
> > AllInfo = MyPath & MyName & "," & MyName & "," & MyInfo
> > Write #1, AllInfo ' Display entry only if it
> > End If ' it represents a directory.
> >
> > End If
> > MyName = Dir ' Get next entry.
> > Loop
> >
> >
>
>
0 Likes