Solved

Excel Macro - List Files and Subfolders with details

Posted on 2010-09-24
3
958 Views
Last Modified: 2012-05-10
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
Comment
Question by:Gonzalo Becerra
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 33753620
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
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33754024
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
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 33754598
Thanks alot!! i check the two solutions and help me alot!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now