473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Directory.Getfiles search pattern

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
4 7901
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Amy L. | last post by:
I am working on some code that will be used in a Windows Service that will monitor specific files in a queue. I would like to get an integer value of the amount of specfic files in a directory. ...
2
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search...
4
by: Mullin Yu | last post by:
e.g. c:\test doc1.txt doc1.pdf doc2.txt doc2.pdf doc3.txt doc4.pdf doc5.txt doc5.pdf
2
by: John Smith | last post by:
Hello all: I am trying to search for more than one extension in a directory at the same time with the following code: string files = Directory.GetFiles(sDir, "*.doc*.dot"); However, this...
2
by: Alphonse Giambrone | last post by:
Is there a way to use multiple search patterns when calling Directory.GetFiles. For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all files with the aspx extension. But what if...
1
by: brian | last post by:
I am using the Directory.GetFiles class and am having problems with the overloaded version. I want to search files. I can use the following and it works fine: Directory.GetFiles(Path, k) Path:...
2
by: OpticTygre | last post by:
I have a directory of 27 files. The files end in either 1.txt, 2.txt, 3.txt, or 4.txt. If I say: For Each filename As String In...
1
by: andrew | last post by:
Hi I have the following script, which lists files within a specified web directory (as long as they are valid extension types). It works, but I would like the file names to be links (i.e. with...
9
by: Julie Smith | last post by:
Hi, Is it just me or does the search pattern parameter in Directory.GetFiles() have a problem with the '?' character? '*.*' works to find all files, but '?.*' does not work to find all files...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.