Hey all,
How can I get the names of all objects inside a folder with the microsoft scripting object?
thanks
Printable View
Hey all,
How can I get the names of all objects inside a folder with the microsoft scripting object?
thanks
Do you mean using the FileSystemObject? If so:
Edit: this gives you files in SubFolders as well, btw.VB Code:
Private sFiles() As String Private Sub Form_Load() Erase sFiles ReDim sFiles(0) GetFiles App.Path For N = LBound(sFiles) To (UBound(sFiles)) Debug.Print sFiles(N) Next N End Sub Private Sub GetFiles(ByVal sFolder As String) Dim fso As New FileSystemObject Dim fCurFolder As Folder Dim fFolder As Folder Dim fFile As File Set fCurFolder = fso.GetFolder(sFolder) For Each fFolder In fCurFolder.SubFolders GetFiles fFolder.Path Next fFolder For Each fFile In fCurFolder.Files If sFiles(0) = vbNullString Then sFiles(0) = fFile.Path Else ReDim Preserve sFiles(UBound(sFiles) + 1) sFiles(UBound(sFiles)) = fFile.Path End If Next fFile End Sub
Something like this?
VB Code:
Dim oFS As FileSystemObject, oFolder As Folder, oFile As File, oSub As Folder Set oFS = New FileSystemObject Set oFolder = oFS.GetFolder("C:\") For Each oSub In oFolder.SubFolders Debug.Print oSub.Path Next oSub For Each oFile In oFolder.Files Debug.Print oFile.Name Next oFile Set oFolder = Nothing Set oFS = Nothing
Thanks, but I can't find the File System Object in the references.
It's part of the Microsoft Scripting Runtime. If it isn't in your References list, browse for scrrun.dll.