Maybe this will help
When prompted, select a file in your top level folder - if there isn't one then create one as an anchor.![]()
'This macro uses the technique of recursion to examine the contents of a folder structure no matter how complex it is. Sub Extract() Dim Filename As Variant ' Set up the empty spreadsheet Cells.Clear Cells(1, 1) = "Folder" Cells(1, 2) = "File" Cells(1, 3) = "Size" Cells(1, 4) = "Name" 'Use the GetOpenFilename function to get a full path description of a typical file Filename = Application.GetOpenFilename() If Filename = False Then Exit Sub 'The GetSubDirectories subroutine is called recursively using the name of the parent folder as the single argument. Call GetSubDirectories(Left(Filename, Len(Filename) - Len(Dir(Filename)) - 1)) Columns.AutoFit End Sub Sub GetSubDirectories(folderspec) Dim fs As Object, f As Object, s As Object Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folderspec) Call GetFiles(f.Path) For Each SubFolder In f.subfolders GetSubDirectories (f.Path & "\" & SubFolder.Name) ' This is a recursive call Next SubFolder End Sub Sub GetFiles(folderspec) Dim fs As Object, f As Object, s As Object Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folderspec) For Each File In f.Files On Error Resume Next Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Value = folderspec ' next available cell in column 1 Cells(Rows.Count, 1).End(xlUp).Offset(0, 1).Value = folderspec & "\" & File.Name Cells(Rows.Count, 1).End(xlUp).Offset(0, 2).Value = File.Size Cells(Rows.Count, 1).End(xlUp).Offset(0, 3).Value = File.Name On Error GoTo 0 Next File End Sub











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks