Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2004

Tip: Looking for answers? Try searching our database.

DirectoryInfo.GetFiles is broken

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Allen - 30 Sep 2004 21:19 GMT
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*"?

Signature

Jonathan Allen

James Curran - 30 Sep 2004 22:25 GMT
> 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.

Signature

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
[quoted text clipped - 6 lines]
>
> Ok, not that I have that out of my system...
Greg Burns - 01 Oct 2004 15:09 GMT
Ah, now that at least sheds some light on the issue.

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

Greg

>> For what possible reason did MS decide that "*.abc" should be interpreted
> as
[quoted text clipped - 4 lines]
> has
> a short name of "123456~1.abc" which matches your pattern.
Willy Denoyette [MVP] - 30 Sep 2004 22:46 GMT
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.

> MSDN> "The matching behavior of searchPattern when the extension is
> exactly
[quoted text clipped - 12 lines]
> as
> "*.abc*"?
Greg Burns - 30 Sep 2004 23:58 GMT
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

> Not sure what OS .NET version you are running, but it works as expected on
> XP SP2 with .NET v1.1 SP1.
[quoted text clipped - 26 lines]
>> as
>> "*.abc*"?
Greg Burns - 01 Oct 2004 13:37 GMT
> I'll try it again after installing SP1 and see what happens...

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

Greg

> My XP SP2 with .NET v1.1 w/o SP1 works just as the documentation states.
>
[quoted text clipped - 60 lines]
>>> interpreted as
>>> "*.abc*"?
Willy Denoyette [MVP] - 01 Oct 2004 14:46 GMT
>> 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.
Greg Burns - 01 Oct 2004 15:06 GMT
>>> I'll try it again after installing SP1 and see what happens...
>>
[quoted text clipped - 22 lines]
>
> 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();
 }
}

}
Willy Denoyette [MVP] - 01 Oct 2004 16:21 GMT
> Your code on my box shows both files! Only change I made was to put my
> test files on C: drive.
[quoted text clipped - 7 lines]
>
> 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.
Joep - 01 Oct 2004 15:09 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.