|
-
Jun 19th, 2001, 02:05 PM
#1
Thread Starter
PowerPoster
how to retrieve all filenames in a folder???
how can I retrieve all filenames in a folder on my LAN?
Thanks
-
Jun 19th, 2001, 02:16 PM
#2
Member
Use the Findfirstfile,FindNextFile,Findclose API. It works great
-
Jun 19th, 2001, 02:21 PM
#3
Member
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.
-
Jun 19th, 2001, 02:22 PM
#4
Thread Starter
PowerPoster
US101 I don't use API often. I would love to learn the way you are suggesting. Can you post that module here?
thanks
-
Jun 19th, 2001, 06:40 PM
#5
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|