Results 1 to 5 of 5

Thread: how to retrieve all filenames in a folder???

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    how to retrieve all filenames in a folder???

    how can I retrieve all filenames in a folder on my LAN?

    Thanks

  2. #2
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45

    Wink

    Use the Findfirstfile,FindNextFile,Findclose API. It works great

  3. #3
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45
    Using the API can be done really quickly, especially if you have done it once, put it in a module, and then made it easy to call from your app.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    US101 I don't use API often. I would love to learn the way you are suggesting. Can you post that module here?

    thanks

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    If you only need the files in a directory try the function below, use dir as it is easy and unless you have a million files in the directory the performance should be reasonable.

    If you are wanting to enumerate all the files in the directory and all of its subdirectories then go for the api Findfirstfile and FindNextfile calls http://pages.about.com/vbmakai/getfiles.htm

    Code:
    Private Sub Command1_Click()
    Dim a As Variant, i As Long
    
    a = EnumDir("c:", "tmp")
    
    If Not IsNull(a) Then
       For i = 1 To UBound(a)
          MsgBox a(i)
       Next i
    Else
        MsgBox "No files found In that directory matching " & _
            "the extension If you passed one."
    End If
    
    End Sub
    
    Function EnumDir(ByVal DirPath As String, Optional ByVal Ext As String) As Variant
        'Nucleus
        Dim files() As String: ReDim files(1 To 100)
        Dim fname$
        Dim lfcount&
        
        EnumDir = Null 'initialise Function
        
        If Right(DirPath, 1) <> "\" Then DirPath = DirPath & "\" 'add path separator If missing
        
        If Len(Dir$(DirPath, vbDirectory)) Then
        
            fname = Dir$(DirPath & "*.*", vbNormal + vbHidden + vbSystem) 'you can include vbdirectory If you need To
            Do While Len(fname)
                If Len(Ext) = 0 Or (Len(Ext) And Right(fname, Len(fname) - InStr(1, fname, ".")) = Ext) Then
                    lfcount = lfcount + 1
                    files(lfcount) = DirPath & fname 'path And file name To array
                    If lfcount Mod 100 = 0 Then ReDim Preserve files(1 To lfcount + 100) 'resize array As required
                End If
                fname = Dir$
            Loop
            
            If lfcount Then ReDim Preserve files(1 To lfcount): EnumDir = files
            
        End If
    End Function

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