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!
LVL 1
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAsked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
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 BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Thanks alot!! i check the two solutions and help me alot!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.