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!

filling an array with filenames from a directory

Status
Not open for further replies.

reszek

Programmer
Jul 3, 2002
16
0
0
CA
I'm trying to fill an array with the files in a certain directory, any help would be appreciated.

zach
 
This should work for you. You will need to add a reference to the Microsoft Scripting Runtime from the Project Menu.

Option Explicit

'Requires Reference to the Microsoft Scripting Runtime
Dim fso As New FileSystemObject
Dim arrFiles() As String

Private Sub Command1_Click()
Dim fFolder As Folder
Dim fFile As File
Dim iX As Long
Dim sPath As String

sPath = "C:\Test" 'Path of Directory
Set fFolder = fso.GetFolder(sPath)
For Each fFile In fFolder.Files
ReDim Preserve arrFiles(iX)
arrFiles(iX) = fFile.Name
iX = iX + 1
Next

End Sub

Hope this helps. [spin]

If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top