By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

DirectoryInfo.GetFiles is broken

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Jonathan Allen" <x@x.x> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
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!) 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...
--
Jonathan Allen

Nov 21 '05 #2

P: n/a
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.

"Jonathan Allen" <x@x.x> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #3

P: n/a
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
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

"Jonathan Allen" <x@x.x> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
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


Nov 21 '05 #4

P: n/a
> 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" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
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
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

"Jonathan Allen" <x@x.x> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
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



Nov 21 '05 #5

P: n/a

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I'll try it again after installing SP1 and see what happens...


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.
Nov 21 '05 #6

P: n/a

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I'll try it again after installing SP1 and see what happens...


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();
}
}

}

Nov 21 '05 #7

P: n/a
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.


Nov 21 '05 #8

P: n/a
Ah, now that at least sheds some light on the issue.

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

Greg

"James Curran" <Ja*********@mvps.org> wrote in message
news:eV*************@TK2MSFTNGP11.phx.gbl...
"Jonathan Allen" <x@x.x> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
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!)

Nov 21 '05 #9

P: n/a

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:ed*************@tk2msftngp13.phx.gbl...
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.
Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.