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