Hi everyone,
i was just wondering how to find multiple files with the same part of filename and just 1 character different.
eg. if i want "abc_$.txt"
i want to find "abc_1.txt", "abc_2.txt", "abc_3.txt", etc within the same directory
thanks buds
Printable View
Hi everyone,
i was just wondering how to find multiple files with the same part of filename and just 1 character different.
eg. if i want "abc_$.txt"
i want to find "abc_1.txt", "abc_2.txt", "abc_3.txt", etc within the same directory
thanks buds
Something like this:
VB Code:
Option Explicit Private Sub Form_Load() Dim sFile As String Dim sDir As String sDir = "C:\" sFile = Dir(sDir & "abc_?.txt", vbArchive) Do Until Len(sFile) = 0 If sFile <> "." And sFile <> ".." Then Debug.Print sDir & sFile End If sFile = Dir Loop End Sub
coooool, it works, thanksssssss
one more question,
what if i want to get all file from a specific directory.
eg. if i want "*.txt"
i want to find all .txt files within the same directory
thanks buds
just change the search string - i'm also pretty sure that . and .. don't get returned if you specify a search string, so you can do:VB Code:
Private Sub Form_Load() Dim sFile As String Dim sDir As String sDir = "C:\" sFile = Dir(sDir & "*.txt", vbArchive) Do While Len(sFile) Debug.Print sDir & sFile sFile = Dir Loop End Sub
Thanks, but sFile giving me a empty string?!? (see code below)
Private Sub Form_Load()
Dim sFile As String
Dim sDir As String
sDir = "C:\"
sFile = Dir(sDir & "*.txt", vbArchive) <-- sFile giving me a empty string?!?
Do While Len(sFile)
Debug.Print sDir & sFile
sFile = Dir
Loop
End Sub
you've definitely got some txt files in C:\ ?
tryVB Code:
sFile = Dir(sDir & "*.txt")
haha, ops, i didn't have any txt file in C:.. it works now, thankss bud