Files in folder

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

Guest

Is there a way to get a list of files from a folder and put that list into a
table?

Every month I need a list of jpegs on a server (usually around 2-3k) to be
put in a report. I can do it using a Mac and Excel, but would love to know if
there is a way to to this via Access.

Thanks for any help.
 
Brian,

The code below will do it. It assumes an already existing table named
tblFiles, whose first field (to strore filenames) is type text. It
requires an appropriate DAO refence to run.

Sub filenames_to_table()
Dim fldr, fls, fl
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.GetFolder("C:\documents\access\")
Set fls = fldr.Files
Set db = CurrentDb()
Set rst = db.OpenRecordset("Files")
On Error Resume Next
For Each fl In fls
If Right(fl.Name, 4) = ".jpg" Then
rst.AddNew
rst.Fields(0) = fl.Name
rst.Update
End If
Next fl
On Error GoTo 0
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub

HTH,
Nikos
 
Back
Top