Directory.GetFiles() コマンドで複数のフィルターを使用しようとしています。
.html ファイルと .css ファイルの両方を一致させたいとします。私はこれを使用しています:
Directory.GetFiles(path,"*.html|*.css");
これがサポートされているというドキュメントはありませんが、最終的には HTML または CSS ファイルのいずれとも一致しません。足りないものはありますか?
Directory.GetFiles 関数は、複数のフィルターをサポートしていません。私の解決策:
string patter = "*.jpg|*.png|*.gif";
string[] filters = patter.Split('|');
foreach(string filter in filters )
{
// call Directory.GetFiles(path, filter) here;
}
foreach ループを回避する降下ソリューションもあります (Linq の助けを借りて):
string[] filters = new[]{"*.jpg", "*.png", "*.gif"};
string[] filePaths = filters.SelectMany(f => Directory.GetFiles(basePath, f)).ToArray();