|
-
Mar 13th, 2006, 05:53 PM
#1
Thread Starter
Fanatic Member
Get all file names from a folder
Hey all,
How can I get the names of all objects inside a folder with the microsoft scripting object?
thanks
-
Mar 13th, 2006, 06:43 PM
#2
Re: Get all file names from a folder
Do you mean using the FileSystemObject? If so:
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
Edit: this gives you files in SubFolders as well, btw.
Last edited by bushmobile; Mar 13th, 2006 at 06:48 PM.
-
Mar 13th, 2006, 06:46 PM
#3
Re: Get all file names from a folder
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
-
Mar 13th, 2006, 10:39 PM
#4
Thread Starter
Fanatic Member
Re: Get all file names from a folder
Thanks, but I can't find the File System Object in the references.
-
Mar 13th, 2006, 10:44 PM
#5
Re: Get all file names from a folder
It's part of the Microsoft Scripting Runtime. If it isn't in your References list, browse for scrrun.dll.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|