Move through directories

G

Guest

Access 2003. I've got the following code which works just fine for retrieving
all of the names of the .mdb files in c:\. However, I need it to move down
through the directory tree and identify all mdb files on the drive. I would
also like to retrieve the size and last date modified. Does anybody have the
code for this.
 
D

Douglas J. Steele

What code? <g>

If you know the name of the file, you can get its size and last modified
date using the FileLen and FileDateTime functions.
 
A

Albert D. Kallal

here is a handy code snip that traversies all the sub dirs.

The code is handy, since it returnes a nice easy to use colection, as the
same code shows


Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub


Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub
 
A

Allen Browne

Albert, the code in the article at:
http://allenbrowne.com/ser-59.html
is actually based on your code, which I picked up from a previous posting.

I adapted it a little, but wanted to say thanks for the logic here. I find
your approach works better than the built-in file object stuff for lots of
reasons: handles zip files better, can be adapted to handle hidden files,
and so on.
 

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