Results 1 to 5 of 5

Thread: Get all file names from a folder

Hybrid View

  1. #1
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Get all file names from a folder

    Do you mean using the FileSystemObject? If so:

    VB Code:
    1. Private sFiles() As String
    2.  
    3. Private Sub Form_Load()
    4.   Erase sFiles
    5.   ReDim sFiles(0)
    6.   GetFiles App.Path
    7.   For N = LBound(sFiles) To (UBound(sFiles))
    8.     Debug.Print sFiles(N)
    9.   Next N
    10. End Sub
    11.  
    12. Private Sub GetFiles(ByVal sFolder As String)
    13.   Dim fso As New FileSystemObject
    14.   Dim fCurFolder As Folder
    15.   Dim fFolder As Folder
    16.   Dim fFile As File
    17.  
    18.   Set fCurFolder = fso.GetFolder(sFolder)
    19.   For Each fFolder In fCurFolder.SubFolders
    20.     GetFiles fFolder.Path
    21.   Next fFolder
    22.   For Each fFile In fCurFolder.Files
    23.     If sFiles(0) = vbNullString Then
    24.       sFiles(0) = fFile.Path
    25.     Else
    26.       ReDim Preserve sFiles(UBound(sFiles) + 1)
    27.       sFiles(UBound(sFiles)) = fFile.Path
    28.     End If
    29.   Next fFile
    30. End Sub
    Edit: this gives you files in SubFolders as well, btw.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width