Reputation: 5151
I've seen this question: Is this a bug in DirectoryInfo.GetDirectories(string searchPattern)?
It is not entirely consistent with my problem, so I'll ask anyway.
My code is:
var pattern = @"file.*";
foreach (var file in Directory.GetFiles(".", pattern))
{
Console.WriteLine(file);
}
In my current directory I have file
and file.txt
. As (un)expected, both files are found.
Is it a bug or is it documented somewhere? I've found this issue on Mono and wanted to file a bug there, but I've checked on VS2012 first and it seems to occur as well...
Of course I know how to filter the result, but it... angers me anyway, so I'd like to know the sources.
Upvotes: 1
Views: 569
Reputation: 17248
This is how Windows (and DOS) interpret wildcards. Unlike UNIX, Windows at one time actually distinguished, internally, between the "name" portion of a filename and the "extension" portion (this is where the notorious "8.3" limit comes from). It doesn't really make this internal distinction anymore, but the legacy of this lives on in Windows.
So Windows/DOS search patterns search for two components, the name, and the extension. The pattern file.*
matches any file named file
with an extension of *
(i.e., any extension at all). Both file
and file.txt
meet this criteria.
I would tend to agree that this doesn't make a lot of sense, but that's how it is.
Upvotes: 6