Connecting Tech Pros Worldwide Forums | Help | Site Map

Directory.Getfiles search pattern

John Dann
Guest
 
Posts: n/a
#1: Nov 14 '06
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

Holger Boskugel
Guest
 
Posts: n/a
#2: Nov 14 '06

re: Directory.Getfiles search pattern


Hello John,
Quote:
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


John Dann
Guest
 
Posts: n/a
#3: Nov 14 '06

re: Directory.Getfiles search pattern


On Tue, 14 Nov 2006 16:53:20 +0100, "Holger Boskugel"
<news.post@vbwebprofi.dewrote:
Quote:
>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
Robinson
Guest
 
Posts: n/a
#4: Nov 14 '06

re: Directory.Getfiles search pattern


Quote:
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()


Holger Boskugel
Guest
 
Posts: n/a
#5: Nov 15 '06

re: Directory.Getfiles search pattern


Hello John,
Quote:
Quote:
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


Closed Thread