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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Listing into Array 1

Status
Not open for further replies.

mfreeze

Programmer
Sep 11, 2003
16
0
0
US
(I am using vb6) Does anyone know how to get a list of filenames and put them into an array? In Foxpro, there is a prewritten function called 'ADIR' that lets you specify a directory, then all filenames in that directory are loaded into an array that you specify. You can even use wildcards such as '*.txt'. Is there anything like this in VB? If not, can someone point me in the right direction as to how you would do this? What I am trying to do is automatically loop through & modify 10-15 files in a directory without having to know the name of, or choose each file.

Thanks,
Mark.
 
Add a reference to Microsoft Scripting Runtime:

Dim fs As FileSystemObject, fol As Folder, fil As File
Dim TempAry() As String, Counter As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
Set fol = fs.GetFolder("C:\Dell\")
ReDim TempAry(fol.Files.Count)
For Each fil In fol.Files
TempAry(Counter) = fil.Name
Counter = Counter + 1
Next
MsgBox "Done!", vbInformation

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top