Hello,
I have the following workbook macro that lists all files/folder names from a directory.
I would like to exclude all folders from being listed (the only folders that would be in this directory would be .zip folders). Ideally I would not want any folders to be listed in the workbook.
Wondering how to tweak this to exclude folder names?
Thanks so much
I have the following workbook macro that lists all files/folder names from a directory.
I would like to exclude all folders from being listed (the only folders that would be in this directory would be .zip folders). Ideally I would not want any folders to be listed in the workbook.
Wondering how to tweak this to exclude folder names?
Thanks so much
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Dim iRow
Sub ListFiles()
iRow = 2
Call ListMyFiles(Range("F1"), Range("F2"))
End Sub
Sub ListMyFiles(mySourcePath, IncludeSubfolders)
ag var --exclude-files={*.zip}
Set MyObject = New Scripting.FileSystemObject
Set mySource = MyObject.GetFolder(mySourcePath)
On Error Resume Next
For Each myFile In mySource.Files
iCol = 1
Cells(iRow, iCol).Value = myFile.Path
iCol = iCol + 1
Cells(iRow, iCol).Value = myFile.Name
iCol = iCol + 1
Cells(iRow, iCol).Value = myFile.Size
iCol = iCol + 1
Cells(iRow, iCol).Value = myFile.DateLastModified
iRow = iRow + 1
Next
If IncludeSubfolders Then
For Each mySubFolder In mySource.SubFolders
Call ListMyFiles(mySubFolder.Path, True)
Next
End If
End Sub</code>