Home All Groups Group Topic Archive Search About

Directory.Getfiles search pattern

Author
14 Nov 2006 2:16 PM
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

Author
14 Nov 2006 3:53 PM
Holger Boskugel
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
Author
14 Nov 2006 4:06 PM
John Dann
On Tue, 14 Nov 2006 16:53:20 +0100, "Holger Boskugel"
<news.p***@vbwebprofi.de> wrote:

>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
Author
14 Nov 2006 4:34 PM
Robinson
> 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()
Author
15 Nov 2006 11:24 AM
Holger Boskugel
Hello John,

Show quoteHide 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