Solved

API to list all files in a directory

Posted on 2001-06-15
5
146 Views
Last Modified: 2010-05-02
I need an example of the api to list all files in a directory.  
0
Comment
Question by:CodeHead
  • 3
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6196428
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 0 total points
ID: 6196429
0
 
LVL 3

Expert Comment

by:hkp
ID: 6196510
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6210418
Thnks for the A grade and for 0 points, too ;)
Cheers
0
 
LVL 1

Author Comment

by:CodeHead
ID: 6210475
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now