list a directory

B

BrianPaul

Question: I have been looking for the code to do the following:

I would like to point to a directory(folder) on my hard drive from access,
then have access populate a table with the filename and locations of all
files. for example produce in the table for example.

C:\ebooks\sports\how to play golf.pdf
C:\ebooks\sports\NCAA 2006 schedule.doc
and so on.

I can do this with one file however Would like to cataloge all the file
locations and path under one directory with a single click instead of having
to do them one at a time.

Thank any help would be appreciated.
 
G

Graham Mandeno

Hi Brian

You can use the Dir() function to return all the files in a directory that
match a wildcard search.

Dir("C:\ebooks\sports\*.*") will return the first file in the folder - for
example:
"how to play golf.pdf"

Then, calling Dir() with no arguments will return all the other files in
turn, until there are no more, when it will return an empty string.

Note that the function returns the filename only, excluding the path.

So you could do something like this:

strPath = "C:\ebooks\sports\"
strNext = Dir(strPath & "*.*")
Do Until strNext = ""
strFile = strPath & strNext
' do something with strFile
strNext = Dir()
Loop
 

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