I recently bumped into a weird functionality from Microsoft:
Let's assume our folder c:\tmp123
contains 3 files -
1.txt
2.txtx
3.txtxt
a) Invocation of Directory.GetFiles(@"C:\tmp123", "*.txt")
yields in 3 returned items.
b) Invocation of Directory.GetFiles(@"C:\tmp123", "*.txtx")
yields in 1 returned items.
According to Microsoft this is the expected behavior (see Note in MSDN).
My questions are:
Why did Microsoft decide to have such a strange functionality?
How can I overcome this problem?
i.e. how do I have a Search Pattern that would return*.txt
extension only and not return*.txtx
,*.txtstarngefunctionality
, etc.?
I'd be willing to wager it's something to do with backward compatibility. I don't see this exact issue mentioned, but this Raymond Chen blogpost mentions a number of oddities in this area: