Hi everyone.
I am trying to scan through all files within a directory and all subdirectories to find files where the name begins with certain characters. Below is code that will accomplish this for a certain directory, but I do not know how to look through the subdirectories within the specified directory. So, the issues are:
1. How do I loop through each subdirectory within a specified directory?
2. I am trying to return the file name, path name (separate from the file name), and modified date. I can return the name. I can return the path, but it includes the name. Is there a way to return just the path?
3. What is the code to return the modified date of the file?
Thanks in advance for any help.
Jason
Sub Scan_Files()
Dim Fso, Fs, Fl
Dim FolderSpec As String
Dim i As Integer
'set directory:
FolderSpec = "\\Server\Files\"
i = 0
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fs = Fso.GetFolder(FolderSpec)
For Each Fl In Fs.Files
If UCase(Left(Fl.Name, 4)) = "A323" Then
Cells(Range("StartHere").Row + i, Range("StartHere").Column) = Fl.Name
Cells(Range("StartHere").Row + i, Range("StartHere").Column + 1) = Fl.Path
i = i + 1
End If
Next Fl
End Sub
Bookmarks