How To List All Folders & Sub-folders Paths, Dirs, & Names In Excel?

Excel folders and Sub-folders

We know that there's no a quick and simple way to get this done at once. But this post will help you get the paths, directories, names, dates created, and the dates last modified of all the folders and sub-folders from a specific directory into a workbook. Just follow the below step-by-step guide. I found this effective workaround from ExtendOffice.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following VBA code: List all folders and subfolder paths and names into the Module Window.

Sub FolderNames()
'Update 20141027
Application.ScreenUpdating = False
Dim xPath As String
Dim xWs As Worksheet
Dim fso As Object, j As Long, folder1 As Object
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Choose the folder"
End With
On Error Resume Next
xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
Set xWs = Application.ActiveSheet
xWs.Cells(1, 1).Value = xPath
xWs.Cells(2, 1).Resize(1, 5).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.getFolder(xPath)
getSubFolder folder1
xWs.Cells(2, 1).Resize(1, 5).Interior.Color = 65535
xWs.Cells(2, 1).Resize(1, 5).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Sub getSubFolder(ByRef prntfld As Object)
Dim SubFolder As Object
Dim subfld As Object
Dim xRow As Long
For Each SubFolder In prntfld.SubFolders
xRow = Range("A1").End(xlDown).Row + 1
Cells(xRow, 1).Resize(1, 5).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified)
Next SubFolder
For Each subfld In prntfld.SubFolders
getSubFolder subfld
Next subfld
End Sub

3. Now press the F5 key to run the code, a window will pop out and choose FolderNames and click Run. A new window will pop out again to choose the folder/directory you want to list the folder and subfolder names, see screenshots:

Unlocking Password-Protected Word, PDF, Excel Documents.

Choose the Folder Directory

4. Click OK, and you will get the folder and sub-folders paths, directories, names, created dates and last modified dates in a new workbook, see sample screenshot:

Folders and sub-folders results

The time your report will be shown on a new workbook depends on the volume of folders and sub-folders. Mine took less than 30 minutes because it has thousands of folders. The lesser folders the faster the report will be extracted.

Your voice matters. Discussions are moderated for civility before being published on the blog. Read my comment policy here.

Previous Post Next Post