473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

DirectoryInfo.GetFiles is broken

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 16 '05 #1
9 1441
"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 16 '05 #2
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 16 '05 #3
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 16 '05 #4
> 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 16 '05 #5

"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 16 '05 #6

"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 16 '05 #7
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 16 '05 #8
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 16 '05 #9

"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 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jonathan Allen | last post by:
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...
2
by: Demetri | last post by:
Using the GetFiles method of the DirectoryInfo instance one can pass in a search pattern of string type. For example: DirectoryInfo di = new DirectoryInfo("C:\temp"); FileInfo fi =...
4
by: Pluto | last post by:
Hi, I want to get a list of files matching certain extensions, such as "*.jpg;*.gif" (i.e. all files ending with .jpg and .gif). I was using DirectoryInfo.GetFiles(string) method....
8
by: Lyners | last post by:
I have code that retrieves all of the file names within a directory. After retriving them, I display the information in a datagrid. What I would like to do is add an extra output column on the...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
5
by: CJ Taylor | last post by:
Hey Everyone, Sorry haven't been around to answer questions as much as usual (or at all for that matter) just been engrossed in a project. Anyways, dealing with an issue using...
13
by: Tom Scales | last post by:
OK, I admit, I am not a VB.NET expert and am still learning, but have run into an annoying problem. I'm writing a program that has to search the file system and therefore processes large numbers...
1
by: jobs | last post by:
Say I only have a single file I want to get information on. How can I adapt this code? Dim dr As DataRow Dim fi As FileInfo Dim dir As New DirectoryInfo(filename) Dim dt As New DataTable...
2
by: RodneyAnonymous | last post by:
Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.