473,387 Members | 1,942 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,387 software developers and data experts.

Directory.GetFiles() Problem

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
that have only a one letter (and infinite extension size) filename. In fact,
it seems to act the same as '*.*'...

Is this by design?

Thanks in advance.
Jul 9 '07 #1
9 4606
Hi Julie,

No, it's not by design, it should work. How do you use it coz that should
work: Directory.GetFiles(<path>, "*.tx?") // or "?n.*"

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

JSHi,
JSIs it just me or does the search pattern parameter in
JSDirectory.GetFiles()
JShave a problem with the '?' character?
JS'*.*' works to find all files, but '?.*' does not work to find all
JSfiles that have only a one letter (and infinite extension size)
JSfilename. In fact, it seems to act the same as '*.*'...
JS>
JSIs this by design?
JS>
JSThanks in advance.
JS>
Jul 10 '07 #2

What version of .Net are you using? I've just tried this in .Net 2.0 (VS
2005) and it works as expected... Only files that had exactly one character
before the point (.) were listed.

Dim listOfFiles As String() = Directory.GetFiles("C:\", "?.*")
For Each filename As String In listOfFiles
Console.WriteLine(filename)
Next

"Julie Smith" <ju***@home.comwrote in message
news:OP*************@TK2MSFTNGP02.phx.gbl...
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
that have only a one letter (and infinite extension size) filename. In
fact, it seems to act the same as '*.*'...

Is this by design?

Thanks in advance.

Jul 10 '07 #3
I have constructed a string pattern for each day (DDMMYYxx.txt). So, for
example the string pattern for today is "110707xx.txt". The search string I
use is "110707??.txt". However, it picked up a file called "1107071.txt". As
you can see, that only fills one ?, not both.

I find this very weird. I might do some test scripts to see if I can
reproduce it outside my application.
"Alex Meleta" <am*****@gmail.comwrote in message
news:15**************************@msnews.microsoft .com...
Hi Julie,

No, it's not by design, it should work. How do you use it coz that should
work: Directory.GetFiles(<path>, "*.tx?") // or "?n.*"

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

JSHi,
JSIs it just me or does the search pattern parameter in
JSDirectory.GetFiles()
JShave a problem with the '?' character?
JS'*.*' works to find all files, but '?.*' does not work to find all
JSfiles that have only a one letter (and infinite extension size)
JSfilename. In fact, it seems to act the same as '*.*'...
JSJSIs this by design?
JSJSThanks in advance.
JS>

Jul 10 '07 #4
Well, I ran two simulations:
string[] files = Directory.GetFiles(dir, "100707??.cnc",
SearchOption.AllDirectories);
foreach (string s in files)
Console.WriteLine(s);

This returned:
\1007070.CNC
\10070701.CNC
\10070702.CNC
\10070703.CNC
\10070704.CNC
\10070705.CNC
\10070706.CNC
\10070707.CNC
\1007071.CNC
\1007072.CNC

As you can see, its not working as expected... However, changing the search
string to "100707?.cnc":
string[] files = Directory.GetFiles(dir, "100707?.cnc",
SearchOption.AllDirectories);

This produces:
\1007070.CNC
\1007071.CNC
\1007072.CNC

This works as expected.

This is .NET 2.0 btw :-)
Jul 10 '07 #5
It is .net 2.0. My previous post to Alex shows my problem with it not
working when two ? are used together. Referring to your example, what if
your search string was "??.*", would it only list files with TWO characters
before the period?
"Daniel Bass" <da***********@blueCAPSbottle.comFIRSTwrote in message
news:ek**************@TK2MSFTNGP02.phx.gbl...
>
What version of .Net are you using? I've just tried this in .Net 2.0 (VS
2005) and it works as expected... Only files that had exactly one
character before the point (.) were listed.

Dim listOfFiles As String() = Directory.GetFiles("C:\", "?.*")
For Each filename As String In listOfFiles
Console.WriteLine(filename)
Next

"Julie Smith" <ju***@home.comwrote in message
news:OP*************@TK2MSFTNGP02.phx.gbl...
>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
that have only a one letter (and infinite extension size) filename. In
fact, it seems to act the same as '*.*'...

Is this by design?

Thanks in advance.


Jul 10 '07 #6
No. It would list files with none, one or two characters before the dot (.)
"Julie Smith" <ju***@home.comwrote in message
news:OB*************@TK2MSFTNGP06.phx.gbl...
It is .net 2.0. My previous post to Alex shows my problem with it not
working when two ? are used together. Referring to your example, what if
your search string was "??.*", would it only list files with TWO
characters before the period?
"Daniel Bass" <da***********@blueCAPSbottle.comFIRSTwrote in message
news:ek**************@TK2MSFTNGP02.phx.gbl...
>>
What version of .Net are you using? I've just tried this in .Net 2.0 (VS
2005) and it works as expected... Only files that had exactly one
character before the point (.) were listed.

Dim listOfFiles As String() = Directory.GetFiles("C:\", "?.*")
For Each filename As String In listOfFiles
Console.WriteLine(filename)
Next

"Julie Smith" <ju***@home.comwrote in message
news:OP*************@TK2MSFTNGP02.phx.gbl...
>>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
that have only a one letter (and infinite extension size) filename. In
fact, it seems to act the same as '*.*'...

Is this by design?

Thanks in advance.



Jul 11 '07 #7
On Tue, 10 Jul 2007 09:06:35 +1000, "Julie Smith" <ju***@home.com>
wrote:
>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
that have only a one letter (and infinite extension size) filename. In fact,
it seems to act the same as '*.*'...

Is this by design?

Thanks in advance.
I believe it is by design. Clearly you're an old hand at the DOS
prompt where ? meant a single character as opposed to .NET where it
means zero or one

--
http://bytes.thinkersroom.com
Jul 11 '07 #8
I wrote a simple test program, and I found that ?? works like *. I dont know why.

If ? means 0 or 1 character, but why did files ending with more than 2 characters show in the results, when I searched for something like "abc??.txt" in the directory? I did not work as doc.
Nov 17 '08 #9
hello wrote:
>
I wrote a simple test program, and I found that ?? works like *. I
dont know why.

If ? means 0 or 1 character, but why did files ending with more than
2 characters show in the results, when I searched for something like
"abc??.txt" in the directory? I did not work as doc.
Can you be more precise about exactly what you tried, and exactly what you
expected? Include a "dir" so we can see what the directory looked like. I
just tried an example, where ? and ?? did exactly what they were supposed
to.

Also, see if the "dir" command provides the same results with the same
glob.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 18 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: S. Han | last post by:
I'm using Directory.GetFiles to enumerate files in a directory. The problem is if you have to enumerate all files + subdirectories recursively, it takes too much memory, and it fails. Is there...
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...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
1
by: Starbuck | last post by:
Hi When the routine below is run it gets to the line - Dim fileEntries As String() = Directory.GetFiles(tString) and then freezes, there is no errors etc, the program just stops responding. The...
2
by: Xagon | last post by:
Hi, I'm a newbie to C#, so forgive me if this is a dumb question. What I want to do is parse a directory of IRC logfiles and dump all the .jpg and .gif links to a text file. If I could get a...
3
by: Michael | last post by:
Hi, I have been using Directory.GetFiles("g://"); in my c# application. But now my boss want's me to do Directory.GetFiles(IP address); I have been unable to figure out how to get this to work....
3
by: cjb | last post by:
Is there a way to get Directory.GetFiles to return multi-language file names? I haven't found any overloads that allow any such parameter. The way I am using it now is: foreach (string d in...
2
by: Nathan Sokalski | last post by:
I have an ASP.NET application which displays the directories & files in a specified directory on the server. I use the System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() to...
0
by: tshad | last post by:
I am trying to do multiple Directory.GetFiles and append the results to one array that I will process. I tried this: string strFiles; strFiles = Directory.GetFiles(SemaSettings.InputFilePath,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.