• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 973
  • Last Modified:

Excel Macro - List Files and Subfolders with details

Hi guys,

I need make a Macro to list in Excel all content of a folder (files, subfolders etc) with details example size and datetime.

Thanks!
0
Gonzalo Becerra
Asked:
Gonzalo Becerra
1 Solution
 
Rory ArchibaldCommented:
Try this - just modify the path and output range in the first sub as required:



Sub TestListFoldersAndFiles()
   FolderListing "C:\test", Range("A1")
End Sub
Sub FolderListing(strFilepath As String, ByRef rngOutput As Range)
   Dim fso As Object, fdrSelected, fdrSub, filTemp
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fdrSelected = fso.GetFolder(strFilepath)
   With rngOutput
      .Value = fdrSelected.Path & " (" & fdrSelected.Files.Count & ")"
      .Font.Bold = True
   End With
   For Each filTemp In fdrSelected.Files
      Set rngOutput = rngOutput.Offset(1)
      rngOutput.Value = filTemp.Name
      rngOutput.Offset(, 1).Value = filTemp.Size
      rngOutput.Offset(, 2).Value = filTemp.DateLastModified
   Next filTemp
   Set rngOutput = rngOutput.Offset(2)
   For Each fdrSub In fdrSelected.SubFolders
      FolderListing fdrSub.Path, rngOutput
   Next fdrSub
   Set fso = Nothing

End Sub

Open in new window

0
 
Patrick MatthewsCommented:
gbecerra,Glad to see you got an answer!You might also want to have a look at this PAQ:http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_25063189.html#a26340696In that comment, I have code that will enumerate the files in a directory, but allow you at runtime to browse to find the directory you want enumerated, and also allow you to indicate whether or not to traverse the subfolders and descendants.Patrick
0
 
Gonzalo BecerraAuthor Commented:
Thanks alot!! i check the two solutions and help me alot!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now