API to list all files in a directory

I need an example of the api to list all files in a directory.  
LVL 1
CodeHeadAsked:
Who is Participating?
 
Richie_SimonettiConnect With a Mentor IT OperationsCommented:
0
 
Richie_SimonettiIT OperationsCommented:
0
 
hkpCommented:
By using Microsoft Scripting Runtime, you can easily get access to folders and files in folders.

Here is a sample which shows the name of each file in the folder C:\.

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Set objFSO = New Scripting.FileSystemObject
Set objFolder = objFSO.GetFolder("C:\")
For Each objFile In objFolder.Files
    MsgBox objFile.Name
Next

Alternately, if you don't want to specify a reference to the "Microsoft Scripting Runtime" DLL, you can use the following:

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\")
For Each objFile In objFolder.Files
    MsgBox objFile.Name
Next


I'll bet this will work for you.

Cheers
:-)



0
 
Richie_SimonettiIT OperationsCommented:
Thnks for the A grade and for 0 points, too ;)
Cheers
0
 
CodeHeadAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.