473,402 Members | 2,061 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,402 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

Jul 21 '05 #1
9 3322
"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

Jul 21 '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

Jul 21 '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


Jul 21 '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



Jul 21 '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.
Jul 21 '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();
}
}

}

Jul 21 '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.


Jul 21 '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!)

Jul 21 '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.
Jul 21 '05 #10

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

Similar topics

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....
4
by: Scott Durrett | last post by:
Does anyone know how to retrieve the file list sorted or how to sort this thing? I'm wanting to sort them by date. Thanks Scott
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: Dominic Marks | last post by:
Hello Group, I'm bemused as to why this code isn't working. It's a very simple loop over the array of FileInfo objects returned from DirectoryInfo.GetFiles. It works fine until the eigth...
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: =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= | last post by:
Hi, I've been trying to use Directory.GetFiles() and also DirectoryInfo.GetFiles() to list files on a remote server using "\\server_name\dir_name" like paths. It works fine on a test windows...
1
by: deerchao | last post by:
I've tried "*.abc;*.123" and "*.abc,*.123", and none of them worked. Is there a way to do so? Thanks!
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.