System.IO.Directory
その機能を提供する静的クラスです。
たとえば、あなたの例は次のようになります。
using System.IO;
bool searchSubfolders = false;
foreach (var filePath in Directory.EnumerateFiles(@"..\bin\Release\XmlConfig",
"*.xml", searchSubfolders))
{
var fileInfo = new FileInfo(filePath); //If you prefer
//Do something with filePath
}
より複雑な例は次のとおりです\
。
var searchPath = @"c:\appname\bla????\*.png";
//Get the first search character
var firstSearchIndex = searchPath.IndexOfAny(new[] {'?', '*'});
if (firstSearchIndex == -1) firstSearchIndex = searchPath.Length;
//Get the clean part of the path
var cleanEnd = searchPath.LastIndexOf('\\', firstSearchIndex);
var cleanPath = searchPath.Substring(0, cleanEnd);
//Get the dirty parts of the path
var splitDirty = searchPath.Substring(cleanEnd + 1).Split('\\');
//You now have an array of search parts, all but the last should be ran with Directory.EnumerateDirectories.
//The last with Directory.EnumerateFiles
//I will leave that as an exercise for the reader.