• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

API to list all files in a directory

I need an example of the api to list all files in a directory.  
0
CodeHead
Asked:
CodeHead
  • 3
1 Solution
 
Richie_SimonettiIT 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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now