|
-
Jun 10th, 2001, 01:06 AM
#1
Thread Starter
Addicted Member
File types
How can i get a list of a file with a file type in one directory. i would like a way that is done all through code
On Error wake up and try again ;-)
___________________________
ICQ # 65392645
email - [email protected]
Visual Studio 6 ent with SP5 Running on XP with an AMD 1.2 ThunderBird with 512 MB RAM And a 120GB primary HDD (very sweet)
-
Jun 10th, 2001, 02:15 AM
#2
Registered User
I didn't quite understand the question, however, if you wanted a list of all the .tmp files in a directory, here is how to do it.
Code:
Option Explicit
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
-
Jun 11th, 2001, 09:14 PM
#3
Thread Starter
Addicted Member
Thats what i was looking for
can i get it to do sub dirs as well
On Error wake up and try again ;-)
___________________________
ICQ # 65392645
email - [email protected]
Visual Studio 6 ent with SP5 Running on XP with an AMD 1.2 ThunderBird with 512 MB RAM And a 120GB primary HDD (very sweet)
-
Jun 11th, 2001, 09:29 PM
#4
Registered User
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
|