This is design behavior. From MSDN (see notes section and examples):
SearchPattern with a file extension of exactly three characters returns files with an extension of three or more characters, where the first three characters correspond to the file extension specified in searchPattern.
You can limit it as follows:
C # 2.0:
string[] fileEntries = Array.FindAll(Directory.GetFiles(pathName, "*.xml"), delegate(string file) { return String.Compare(Path.GetExtension(file), ".xml", StringComparison.CurrentCultureIgnoreCase) == 0; });
C # 3.0:
string[] fileEntries = Directory.GetFiles(pathName, "*.xml").Where(file => Path.GetExtension(file).Length == 4).ToArray(); // or string[] fileEntries = Directory.GetFiles(pathName, "*.xml").Where(file => String.Compare(Path.GetExtension(file), ".xml", StringComparison.CurrentCultureIgnoreCase) == 0).ToArray();
source share