JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 788
- Office Version
- 365
- Platform
- Windows
Hi,
Can anyone suggest code that can do this efficiently?
I want full filepath output
I tried using Scripting.FileSystemObject but it's slow if there are many Subfolders
If not VBA, maybe powershell?
I tried using the term command but it cuts off if the filepath is long
Any help appreciated
Current code
Can anyone suggest code that can do this efficiently?
I want full filepath output
I tried using Scripting.FileSystemObject but it's slow if there are many Subfolders
If not VBA, maybe powershell?
I tried using the term command but it cuts off if the filepath is long
Any help appreciated
Current code
VBA Code:
Sub getfiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object, sf
Dim i As Long, colFolders As New Collection, ws As Worksheet
i = 1
Set ws = ActiveSheet
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.getfolder("C:\imagex")
colFolders.Add oFolder 'start with this folder
Do While colFolders.Count > 0 'process all folders
Set oFolder = colFolders(1) 'get a folder to process
colFolders.Remove 1 'remove item at index 1
For Each oFile In oFolder.Files
ws.Cells(i + 1, 1) = oFolder.Path
ws.Cells(i + 1, 2) = oFile.Name
i = i + 1
Next oFile
'add any subfolders to the collection for processing
For Each sf In oFolder.subfolders
colFolders.Add sf 'add to collection for processing
Next sf
Loop
End Sub