By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Directory.Getfiles search pattern

P: n/a
Is there a way to limit the search pattern for Directory.Getfiles to
an exact number of characters. For example I want to see all the files
fitting the pattern "*.abc" but excluding "*.abcd". The default
behaviour seems to include .abcd when searching for just"*.abc", which
I suppose is logical in one way, but not what I want.

JGD
Nov 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hello John,
Is there a way to limit the search pattern for Directory.Getfiles to
an exact number of characters. For example I want to see all the files
fitting the pattern "*.abc" but excluding "*.abcd". The default
behaviour seems to include .abcd when searching for just"*.abc", which
I suppose is logical in one way, but not what I want.
Have you tried """*.abc""" ? I've read in an article that on shell you
can limit it to only the exact match if you place "" around.
Regards

Holger
Nov 14 '06 #2

P: n/a
On Tue, 14 Nov 2006 16:53:20 +0100, "Holger Boskugel"
<ne*******@vbwebprofi.dewrote:
>Have you tried """*.abc""" ? I've read in an article that on shell you
can limit it to only the exact match if you place "" around.
Thanks for the idea but 'Illegal characters in path' runtime error
with """*.abc""" (sic).

""*.abc"" gives a design time error.

Looks like I might have to do "*.abc" and then weed out the unwanted
file names but it's a pain and not totally trivial to code in my proc,
which places the results of the Directory.Getfiles in a string array.
The array is then used for other purposes. Nothing insuperable of
course, just a little messy. Getting the desired result from "*.abc"
would have made life significantly simpler.

JGD
Nov 14 '06 #3

P: n/a
Looks like I might have to do "*.abc" and then weed out the unwanted
file names but it's a pain and not totally trivial to code in my proc.

It's quite trivial to weed out the unwanted items, try something like the
following:


Dim theFiles() As String = Directory.GetFiles(thePath, thePattern)

Dim theList As New List(Of String)
For Each theFile As String In theFiles

If <implement search pattern(theFile) then
theList.Add(theFile)
End If

Next

theFiles = theList.ToArray()
Nov 14 '06 #4

P: n/a
Hello John,
Have you tried """*.abc""" ? I've read in an article that on shell you
can limit it to only the exact match if you place "" around.

Thanks for the idea but 'Illegal characters in path' runtime error
with """*.abc""" (sic).

""*.abc"" gives a design time error.

Looks like I might have to do "*.abc" and then weed out the unwanted
file names but it's a pain and not totally trivial to code in my proc,
which places the results of the Directory.Getfiles in a string array.
The array is then used for other purposes. Nothing insuperable of
course, just a little messy. Getting the desired result from "*.abc"
would have made life significantly simpler.
If this is not working, so you should use the solution Robinson
mentioned.
Regards

Holger
Nov 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.