Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does DirectoryInfo.GetFiles() match files that don't match the mask?

Tags:

c#

windows

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

like image 848
scottm Avatar asked Apr 24 '09 15:04

scottm


2 Answers

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?

like image 100
Dean Avatar answered Oct 06 '22 01:10

Dean


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".

like image 36
Joe White Avatar answered Oct 06 '22 00:10

Joe White