Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

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

Reply
 
Old 05-19-2009   #1 (permalink)
Thomas Gagne


 
 

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

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

My System SpecsSystem Spec
Old 05-19-2009   #2 (permalink)
Thomas Gagne


 
 

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

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.
My System SpecsSystem Spec
Old 05-22-2009   #3 (permalink)
Morten Wennevik [C# MVP]


 
 

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

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.

--
Happy Coding!
Morten Wennevik [C# MVP]


"Thomas Gagne" wrote:
Quote:

> 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.
>
My System SpecsSystem Spec
Old 05-24-2009   #4 (permalink)
Thomas Gagne


 
 

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

After realizing that I decided Regex's methods would do the trick. Only
a few extra lines of code.
My System SpecsSystem Spec
Old 07-14-2009   #5 (permalink)
Robin


 
 

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

On May 24, 10:25*pm, Thomas Gagne <TandGandGA...@xxxxxx> wrote:
Quote:

> 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. =)
My System SpecsSystem Spec
Old 07-15-2009   #6 (permalink)
Robin


 
 

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

On Jul 15, 11:53*am, Robin <theinht...@xxxxxx> wrote:
Quote:

> On May 24, 10:25*pm, Thomas Gagne <TandGandGA...@xxxxxx> wrote:
>
Quote:

> > 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. =)

I got it now. we have to filter by using Regex.IsMatch()
function.thank you.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Replace special characters in filenames - how? PowerShell
Search port wildcards General Discussion
filenames with [ characters PowerShell
Wildcards starting with ~ PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46