Solved

Excel Macro - List Files and Subfolders with details

Posted on 2010-09-24
3
964 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

831 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