List of files in a directory

  • Thread starter Thread starter SAC
  • Start date Start date
S

SAC

I would like to populate a table with a list of file names in a
subdirectory. Each file name would be on a separate row of the table.

I don't know how to do this within access. I need to set the directory
path, then do a directory showing only the file names and insert each name
onto a table record.

In DOS I would:

CD to the folder path
dir /b > temp.txt

Since the temp.txt file would have the file names in it then I could import
it into my table.

Can I automate this with dao and vba?

Thanks.
 
You can use the built-in Dir function.

Dim strPath As String
Dim strFile As String

' Set the path
strPath = "c:\"
' Retrieve the first entry.
strFile = Dir(strPath)
Do While Len(strFile) > 0
Debug.Print strFile
' Get next entry.
strFile = Dir
Loop
 
Back
Top