Import file size and file names from a directory

  • Thread starter Thread starter zahid
  • Start date Start date
Z

zahid

I have a lot of pdf files in a directory.
I want to extract file names and file sizes in excel or access.
Can you advise me any tool or code to do above task.
Please also tell, If this can be done in Frontpage.
 
try
Sub FindFiles()
mypath = "c:\a"
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = mypath
.SearchSubFolders = True 'False
.MatchTextExactly = False
.filename = ".xls"
If .Execute(msoSortOrderDescending) > 0 Then
'MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
If Mid(.FoundFiles(i), Len(mypath) + 1, 2) <> " " Then
Cells(i + lastrow, 1).Value = FileLen(.FoundFiles(i))
'Cells(i + lastrow, 2).Value = FileDateTime(.FoundFiles(i))
Cells(i + lastrow, 3).Value = Right(.FoundFiles(i), _
Len(.FoundFiles(i)) - Len(mypath) - 1)
End If
Next i
Else
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top