|
-
Nov 23rd, 2006, 09:06 AM
#1
Thread Starter
Junior Member
How to find multiple files with the same part of filename?
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
-
Nov 23rd, 2006, 09:10 AM
#2
Re: How to find multiple files with the same part of filename?
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
-
Nov 23rd, 2006, 09:55 AM
#3
Thread Starter
Junior Member
Re: How to find multiple files with the same part of filename?
coooool, it works, thanksssssss
-
Nov 23rd, 2006, 10:50 AM
#4
Thread Starter
Junior Member
Re: How to find multiple files with the same part of filename?
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
-
Nov 23rd, 2006, 10:57 AM
#5
Re: How to find multiple files with the same part of filename?
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
-
Nov 23rd, 2006, 11:07 AM
#6
Thread Starter
Junior Member
Re: How to find multiple files with the same part of filename?
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
-
Nov 23rd, 2006, 11:15 AM
#7
Re: How to find multiple files with the same part of filename?
you've definitely got some txt files in C:\ ?
try
VB Code:
sFile = Dir(sDir & "*.txt")
-
Nov 23rd, 2006, 11:26 AM
#8
Thread Starter
Junior Member
Re: How to find multiple files with the same part of filename?
haha, ops, i didn't have any txt file in C:.. it works now, thankss bud
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
|