If you're looking to iterate folders and return a file listing perhaps the below code would suffice?
This will return, to a new timestamped worksheet, the full file paths of any / all jpgs found below F:\New folder\30\
Code Adapted from: https://analystcave.com/vba-dir-func...e-directories/
modify the file path in initial subroutine as necessary etc...
Sub Test()
With Sheets.Add
.Name = Format(Now, "yyyymmddhhmmss")
End With
TraversePath "F:\New folder\30\"
End Sub
Sub TraversePath(path As String)
Dim currentPath As String, directory As Variant
Dim dirCollection As Collection
Set dirCollection = New Collection
currentPath = Dir(path, vbDirectory)
'Explore current directory
Do Until currentPath = vbNullString
Debug.Print currentPath
If Left(currentPath, 1) <> "." And _
(GetAttr(path & currentPath) And vbDirectory) = vbDirectory Then
dirCollection.Add currentPath
ElseIf InStr(1, currentPath, ".jpg", vbTextCompare) > 0 Then
With ActiveSheet
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Value = path & "\" & currentPath
End With
End If
currentPath = Dir()
Loop
'Explore subsequent directories
For Each directory In dirCollection
Debug.Print "---SubDirectory: " & directory & "---"
TraversePath path & directory & "\"
Next directory
End Sub
Bookmarks