Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

Bug in Directory.GetFiles?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob L. - 12 Jul 2005 05:56 GMT
Hi everyone,

I have a file in my C:\Temp folder called "Test 0 A.txt" (there are two
spaces). If I call Directory.GetFiles("C:\Temp", "*1*.txt"), it returns the
file, even though the pattern does not match. If I do a search in Windows
Explorer, the file does *not* show up. Is there a way I can get .NET to
behave like the Windows OS (2000 and XP both work this way), or am I forced
to code my own pattern matching routine?

Thanks!
Bob L.
Mattias Sjögren - 12 Jul 2005 07:40 GMT
>I have a file in my C:\Temp folder called "Test 0 A.txt" (there are two
>spaces). If I call Directory.GetFiles("C:\Temp", "*1*.txt"), it returns the
>file, even though the pattern does not match.

It probably matches the short file name (which may be something like
Test0~1.txt). Try doing a dir /x in a command window to see what the
short names are.

>If I do a search in Windows
>Explorer, the file does *not* show up. Is there a way I can get .NET to
>behave like the Windows OS (2000 and XP both work this way), or am I forced
>to code my own pattern matching routine?

Well you can turn off short file name generation with some registry
setting. But that may not be an option unless you control the client
machines.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Bob L. - 12 Jul 2005 21:38 GMT
It seems your hunch is right. So Windows 2000 searches long file names, but
.NET does not? Unbelievable. And all this time I thought that both products
came from the same company!

- Bob L.

> >I have a file in my C:\Temp folder called "Test 0 A.txt" (there are two
> >spaces). If I call Directory.GetFiles("C:\Temp", "*1*.txt"), it returns the
[quoted text clipped - 14 lines]
>
> Mattias
Gabriel Lozano-Morán - 13 Jul 2005 06:50 GMT
The .NET Framework v1.1 uses functions from the Windows Kernel to find files
and the search will include both short and long file names. (See
FindFirstFile and FindNextFile in the MSDN Library)

Gabriel Lozano-Morán
Bob L. - 13 Jul 2005 17:46 GMT
I understand that .NET uses the APIs. The problem is that neither one of
them works properly with long file names (or at least files names with
spaces). Please read the original problem again.

One of the requirements of my application is that it produces the same
results as a file search in Windows Explorer (that is, open Windows Explorer
and click the Search button). The Windows Explorer search does not use
FindFirstFile and FindNextFile, and thus behaves correctly with long file
names. That's what I need to do, and cannot with .NET or with the API.

- Bob L.

> The .NET Framework v1.1 uses functions from the Windows Kernel to find files
> and the search will include both short and long file names. (See
> FindFirstFile and FindNextFile in the MSDN Library)
>
> Gabriel Lozano-Morán
Mattias Sjögren - 14 Jul 2005 07:51 GMT
>The Windows Explorer search does not use
>FindFirstFile and FindNextFile,

Are you sure? Perpahs it just filters out any files where the short
name matches but the long name doesn't. Shouldn't be too hard to do
yourself.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.