Inventory a drive

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Dir() and similar functions, how can I inventory a hard drive, reading
all the directories/subdirectories etc. for all the files on it? I want to
read these paths/filenames with their dates/sizes into a table and so some
duplicate file searching/resolution.

Better ideas are always welcome.
 
KitCaz said:
Using Dir() and similar functions, how can I inventory a hard drive, reading
all the directories/subdirectories etc. for all the files on it? I want to
read these paths/filenames with their dates/sizes into a table and so some
duplicate file searching/resolution.


Maybe you can adapt this procedure to populate your table.

Public Sub ListFiles(path As String)
Dim SubDirs(255) As String
Dim strFile As String
Dim K As Integer, J As Integer

On Error GoTo ErrHandler

Debug.Print path
' Build list of subdirectories
strFile = Dir(path & "\", vbDirectory)
Do Until strFile = ""
If GetAttr(path & "\" & strFile) = vbDirectory _
And strFile <> "." And strFile <> ".." Then
SubDirs(K) = path & "\" & strFile
K = K + 1
End If
strFile = Dir
Loop

' Process each workbook
strFile = Dir(path & "\*.XLS")
Do Until strFile = ""
Debug.Print , strFile
strFile = Dir
Loop

' Repeat all this for each subdirectory
For J = 0 To K - 1
ListFiles SubDirs(J)
Next J

ExitHere:
Exit Sub

ErrHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitHere
End Sub
 
Back
Top