DirectoryInfo.GetFiles is broken

  • Thread starter Thread starter Jonathan Allen
  • Start date Start date
J

Jonathan Allen

MSDN> "The matching behavior of searchPattern when the extension is exactly
three characters long is different from when the extension is more than
three characters long. A searchPattern of exactly three characters returns
files having an extension of three or more characters. A searchPattern of
one, two, or more than three characters returns only files having extensions
of exactly that length."

WHAT THE <BLEEP> WERE THEY THINKING!

Ok, not that I have that out of my system...

For what possible reason did MS decide that "*.abc" should be interpreted as
"*.abc*"?
 
Jonathan Allen said:
For what possible reason did MS decide that "*.abc" should be interpreted as
"*.abc*"?

Because when you say "*.abc", it doesn't know if you are referring to
the file's longname or it's shortname. A file name "1234567890.abcdef" has
a short name of "123456~1.abc" which matches your pattern.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 
Not sure what OS .NET version you are running, but it works as expected on
XP SP2 with .NET v1.1 SP1.

so if a directory contains:
readme.abc
and
readme.abcde

GetfFiles(*.abc")
only returns readme.abc

Willy.
 
My XP SP2 with .NET v1.1 w/o SP1 works just as the documentation states.

GetfFiles("*.abc") finds:

c:\readme.abc
c:\readme.abcde

JUST WHAT THE <BLEEP> WERE THEY THINKING? :^)

I'll try it again after installing SP1 and see what happens...

Greg

Imports System
Imports System.IO

Public Class Test
Public Shared Sub Main()
Try
Dim di As DirectoryInfo = New DirectoryInfo("c:\")

Console.WriteLine("The number of files in {0} ending with .abc
is {1}", _
di, di.GetFiles("*.abc").Length)

Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try

Console.ReadLine()
End Sub
End Class
 
I'll try it again after installing SP1 and see what happens...

FYI: SP1 behaves the same way. As would be expected.

Greg
 
Greg Burns said:
FYI: SP1 behaves the same way. As would be expected.

Greg

On XP SP2 and .NET v1.1 SP2

public static void Main()
{
string[] dirs = Directory.GetFiles(@"f:\", "*.abc");
Console.WriteLine("The number of files is {0}.", dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}

prints:
The number of files is 1.
f:\readme.abc

when f:\ contains redme.abc and readme.abcde
as expected.

Willy.
 
Willy Denoyette said:
Greg Burns said:
FYI: SP1 behaves the same way. As would be expected.

Greg

On XP SP2 and .NET v1.1 SP2

public static void Main()
{
string[] dirs = Directory.GetFiles(@"f:\", "*.abc");
Console.WriteLine("The number of files is {0}.", dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}

prints:
The number of files is 1.
f:\readme.abc

when f:\ contains redme.abc and readme.abcde
as expected.

Willy.

Your code on my box shows both files! Only change I made was to put my test
files on C: drive.

The number of files is 2.
c:\readme.abc
c:\readme.abcde


Not sure what "is to be expected". Common sense says one thing. The
documentation says another. All my test have followed what the docs say.

Greg


using System;
using System.IO;

namespace ConsoleApplication2
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
string[] dirs = Directory.GetFiles(@"c:\", "*.abc");
Console.WriteLine("The number of files is {0}.", dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
Console.ReadLine();
}
}

}
 
Ah, now that at least sheds some light on the issue.

Now, why cannot Willy and I get the same results...

Greg
 
On XP Pro, VS.NET Pro 7.1.3088, Net 1.1.4322 SP1 I get both. I will try SP2
and see what that gets me.
 
Your code on my box shows both files! Only change I made was to put my
test files on C: drive.

The number of files is 2.
c:\readme.abc
c:\readme.abcde


Not sure what "is to be expected". Common sense says one thing. The
documentation says another. All my test have followed what the docs say.

Greg

Directory.GetFiles calls Win32 API's FindFirstFile - FindNextFile , so IMO
"the expected behavior" is what these API return.
To be sure I wrote following C program, and the results are exactly the same
when run with f:\*.abc as argument.

#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(argv[1], &FindFileData);
printf ("First file: %s\n", FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData))
{
printf ("Next file: %s\n", FindFileData.cFileName);
}
FindClose(hFind);
return (0);
}

Note that the FS is NTFS and I have NET v2.0 beta installed as well.

Willy.
 
Back
Top