Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File listing function?

Status
Not open for further replies.

EvilCabal

Programmer
Jul 11, 2002
206
CA
Hello,

I am looking for a simple function that could give me the file listing for a given directory. As far as I know access doesn't have one. I've also looked in the Win Api functions listing without success. I'm confident there are many ways to do that but I can't find them!

Thank you for the help.
 
You can use the Dir function. Example below returns all files in a specific path as a string delimited by commas. This is just an example see help for more info..

Function mDirListing(ByVal vstrPath As String) As String
Dim strCurrentFile As String

strCurrentFile = Dir(vstrPath & "*.*")

If strCurrentFile <> vbNullString Then
mDirListing = strCurrentFile

Do While strCurrentFile <> vbNullString
strCurrentFile = Dir
If strCurrentFile <> vbNullString Then
mDirListing = mDirListing & &quot;, &quot; & strCurrentFile
End If
Loop

End If

End Function

'Call the function like this..

Sub test()
MsgBox mDirListing(&quot;C:\&quot;)
End Sub

There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top