Directory.Getfiles search pattern

  • Thread starter Thread starter John Dann
  • Start date Start date
J

John Dann

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
 
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
 
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
 
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()
 
Hello John,
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
 
Back
Top