?
Solved

Excel Macro - List Files and Subfolders with details

Posted on 2010-09-24
3
Medium Priority
?
970 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 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 93

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Introduction to Processes
Starting up a Project

801 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