This behavior is by design. From MSDN (look at the note section and examples given):
A searchPattern with a file extension
of exactly three characters returns
files having an extension of three or
more characters, where the first three
characters match the file extension
specified in the searchPattern.
You could 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;
});
// or
string[] fileEntries = Array.FindAll(Directory.GetFiles(pathName, "*.xml"),
delegate(string file) {
return Path.GetExtension(file).Length == 4;
});
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();