6 replies
by bmckeehan
by achp
From the MSDN:
Sub ShowFileList(folderspec)
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s= s & vbCrLf
Next
MsgBox s
End Sub
by bmckeehan
by gbworld
This example is VB, but it shows a simple method which will not require REDIMming an array with each loop.
Dim aryFiles As Variant
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim strFiles As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Program Files")
For Each objFile In objFolder.Files
'* Load file names into comma delim str
strFiles = strFiles & objFile.Name & ","
Next objFile
'* Puts strFiles into the variant array
aryFiles = Split(strFiles, ",")
The other option is to continuously REDIM the array inside the for ... next loop. This is the easiest way if you intend on a multi-dimensional array.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
by bmckeehan
by bmckeehan
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending