Don't see any questions similar to what I am looking for.
I have about 20k+ PDFs stored in various locations on my C drive. I don't have a complete list of what is available or when they were created.
What I am looking to do is find the names, size and dates that the file was created. These would need to be recorded in an Excel spreadsheet
Note: Some of the PDFs are buried about 6 or 7 folders deep, while some are only 1 folder deep.
Can anybody suggest a way of automatically do it?
I have tried using this code*:
Sub ListAllFiles()
Dim fs As FileSearch, ws As Worksheet, i As Long
Dim r As Long
Set fs = Application.FileSearch
With fs
.SearchSubFolders = True '
.FileType = msoFileTypeAllFiles 'can modify to just Excel files eg with msoFileTypeExcelWorkbooks
.LookIn = "H:\My Desktop"
If .Execute > 0 Then
Set ws = Worksheets.Add
r = 1
For i = 1 To .FoundFiles.Count
If Right(.FoundFiles(i), 3) = ".pdf" Or Right(.FoundFiles(i), 3) = ".tif" Then
ws.Cells(r, 1) = .FoundFiles(i)
r = r + 1
End If
Next
Else
MsgBox "No files found"
End If
End With
End Sub
However, this seems to return an issue in the 4th line - application.filesearch
I have also tried this*, which works well, but doesn't go into the folders:
Sub ListAllFile()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("H:\My Desktop")
ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & " are:"
'Loop through the Files collection
For Each objFile In objFolder.Files
If UCase$(Right$(objFile.Name, 4)) = ".PDF" Then
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = Replace$(UCase$(objFile.Name), ".PDF", "")
End If
Next
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Any help would be gratefully appreciated.
- these are codes that I found on the net