tags:

views:

563

answers:

4

Basically, I have this code:

DirectoryInfo dir = new DirectoryInfo(@"\\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL\00806\");
FileInfo[] files = dir.GetFiles("200810*");

I expect it to match any files starting with 200810. However, it's matching files named

*20070618_00806.bak and 20070817_00806.bak* (the stars aren't in the filename, that was the only way I could include the underscore)

I tried it with dir from a command prompt, and it matches those files also. Why?

Edit:

Maybe using C: as the example was not a good thing. The directory I'm actually querying is a network share \\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL\00806\

If checking against the short name has anything to do with it, won't 20070817_00806.bak be 200708~1.bak? That doesn't match either

+3  A: 

I can't reproduce this, either from the command line or in a test app:

c:\Users\Jon\Test>echo > 20070618_00806.bak

c:\Users\Jon\Test>echo > 2007081700806.bak

c:\Users\Jon\Test>dir 200810*
 Volume in drive C is OS
 Volume Serial Number is B860-7E20

 Directory of c:\Users\Jon\Test

File Not Found

And the C# app:

using System;
using System.IO;

class Test
{
    static void Main()
    {
        foreach (var file in new DirectoryInfo(".").GetFiles("200810*"))
        {
            Console.WriteLine(file);
        }
    }
}

(This doesn't print any results.)

Perhaps there's some OS setting somewhere which is making a difference... which OS are you using? (I'm on 32-bit Vista.)

Jon Skeet
@Jon Windows XP
scottm
Same behavior for me, too.
0xA3
When I run this test locally it works as expected. I even tried it on another network share and it works as expected.
scottm
+9  A: 

msdn states that

"Because this method checks against file names with both the 8.3 file name format and the long file name format, a search pattern similar to "1.txt" may return unexpected file names. For example, using a search pattern of "1.txt" will return "longfilename.txt" because the equivalent 8.3 file name format would be "longf~1.txt"."

Could this be the cause?

Dean
I don't think so, but I could be wrong.
scottm
+1  A: 

GetFiles will search the long file name and the short filename...it's not somehow matching short file names is it?

+4  A: 

Try this from the command line:

dir /x 200810*

The "/x" will make it show the short filenames, as well as the long filenames. This would let you see whether the short filename actually does start with "200810".

Joe White
Hooray! That is the problem. I'll give you an upvote
scottm