Create a list of all files in a folder

L

lombardm

I would like to create a list of all the files in a folder, but am
fumbling with the detail. The code below only lists the files with
extension ".doc" in the folder in question. There ore other types of
files (.pdf, .tiff) but they are not listed. Any reason why, and how
does one work around it.

Thanks
Laurence

Sub test2()
With Application.FileSearch
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Sheets("Sheet1").Range("A" & i).Value = .FoundFiles(i)
Next i
End With


End Sub
 
L

lombardm

I would like to create alistofallthefilesin afolder, but am
fumbling with the detail. The code below only lists thefileswith
extension ".doc" in thefolderin question. There ore other types offiles(.pdf, .tiff) but they are not listed. Any reason why, and how
does one work around it.

Thanks
Laurence

Sub test2()
With Application.FileSearch
    For i = 1 To .FoundFiles.Count
        MsgBox .FoundFiles(i)
      Sheets("Sheet1").Range("A" & i).Value = .FoundFiles(i)
    Next i
End With

End Sub

I think I must do some homework before requesting help. A quick search
of this group reveals several discussions on this topic, so I need to
follow that up first. Excuse the hasty post!
 
D

Don Guillett

Probably cuz you didn't specify where to look. From HELP
With Application.FileSearch
.LookIn = "c:\my documents"
.FileType = msoFileTypeExcelWorkbooks
.Execute
End With
============
You may like this
Sub FindFiles()
Application.ScreenUpdating = False
Dim FN As String
Dim ThisRow As Long
Dim FileLocation As String
FileLocation = "c:\yourfoldernamehere\*.*"
FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
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

Top