BUG? DirectoryInfo.GetFiles() wildcards fail on filenames > 8 characters

T

Thomas Gagne

When file names have more than eight characters, directory wildcards
seems to stop working.

I created two files shown in the directory listing below. In my C#
program I was hoping to distinguish one from from another using
DirectoryInfo.GetFiles("abc??????????????") to only return the first
file. As it turns out, when file names are longer than eight characters
the wildcards stop working.

In the script below, I do a DIR, a DIR abc???? and a DIR abc?????. Note
how both filenames show-up in the last query even though both of them
have more than five characters following "abc".

I can't be the first one to notice this. Is there another DirectoryInfo
class substitute I should be using?


C:\Users\Thomas\testdir>dir
Volume in drive C is WINDOWS
Volume Serial Number is 4CD9-E01A

Directory of C:\Users\Thomas\testdir

05/19/2009 12:24 PM <DIR> .
05/19/2009 12:24 PM <DIR> ..
05/19/2009 12:22 PM 15 abc20090519123456
05/19/2009 12:23 PM 27 abcde20090519123456
2 File(s) 42 bytes
2 Dir(s) 46,888,103,936 bytes free

C:\Users\Thomas\testdir>dir abc????
Volume in drive C is WINDOWS
Volume Serial Number is 4CD9-E01A

Directory of C:\Users\Thomas\testdir

File Not Found

C:\Users\Thomas\testdir>dir abc?????
Volume in drive C is WINDOWS
Volume Serial Number is 4CD9-E01A

Directory of C:\Users\Thomas\testdir

05/19/2009 12:22 PM 15 abc20090519123456
05/19/2009 12:23 PM 27 abcde20090519123456
2 File(s) 42 bytes
0 Dir(s) 46,888,103,936 bytes free
 
T

Thomas Gagne

I just discovered it's an 8.3 problem going back to the DOS days.

What a horrible piece of luggage for MS to be carrying around that it's
still not fixed.
 
T

Thomas Gagne

I just discovered it's an 8.3 problem going back to the DOS days.

What a horrible piece of luggage for MS to be carrying around that it's
still not fixed.
 
M

Morten Wennevik [C# MVP]

Hi Thomas,

I'm afraid .Net uses the win32 way when dealing with file names and every
now and then you may stumble upon shortcomings like not being able to open
ntfs file names ending with several white space characters. Although
perfectly legal on ntfs, win32 does not support it. It looks like win32 does
its search on the 8.3 version of the filename if the search pattern is less
or equal to 8.3, or possibly combine two searches. This would mean that it
won't get any better even if you use the win32 methods like FindFirstFile
directly.

There are talks about changing how .net deals with the file system, but to
my knowledge there are no changes yet (as of .Net 4).

I fear in your case the only option is to change the search pattern such
that it does not match the 8.3 name of the files.
 
M

Morten Wennevik [C# MVP]

Hi Thomas,

I'm afraid .Net uses the win32 way when dealing with file names and every
now and then you may stumble upon shortcomings like not being able to open
ntfs file names ending with several white space characters. Although
perfectly legal on ntfs, win32 does not support it. It looks like win32 does
its search on the 8.3 version of the filename if the search pattern is less
or equal to 8.3, or possibly combine two searches. This would mean that it
won't get any better even if you use the win32 methods like FindFirstFile
directly.

There are talks about changing how .net deals with the file system, but to
my knowledge there are no changes yet (as of .Net 4).

I fear in your case the only option is to change the search pattern such
that it does not match the 8.3 name of the files.
 
T

Thomas Gagne

After realizing that I decided Regex's methods would do the trick. Only
a few extra lines of code.
 
T

Thomas Gagne

After realizing that I decided Regex's methods would do the trick. Only
a few extra lines of code.
 
R

Robin

After realizing that I decided Regex's methods would do the trick.  Only
a few extra lines of code.

Could you please show us how to implement the code?

Thank you. =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top