How Can I generate a List of files in a given directory?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to look up file names in a given directory and then list those fiels
in an excel spreadsheet.

I want to look in "C:\...\" for all *.txt files.
put file path, name, and extension in a table called files.
the table has only one field.
then
I would like to export the table to excel and then delete the table.

I have tried several of the solutions for this, but nothing works.

The only purpose this db has is to create this list.

Please help.

Matthew
 
Why not do it directly from Excel? You could write a macro in VBA using the
FileSearch Object and get the same results without having to go through
Access.
 
I have the code to do it in excel, but want to do it from Access for this and
future requirements because what they want to do is really better handled by
access.

Matthew
 
Try using the Filesearch Object.

Here is an example of it using VBA code:

Dim fs As FileSearch
Set fs = Application.FileSearch

With fs
.NewSearch
.LookIn = sdir
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
FullFileName = .FoundFiles(i)
MsgBox "File: " & .foundFiles(i), vbInformational, "File Found"
Next i
End With
 
Back
Top