string fileName = "";
string sourcePath = @"C:\vish";
string targetPath = @"C:\SR";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
string pattern = @"23456780";
var matches = Directory.GetFiles(@"c:\vish")
.Where(path => Regex.Match(path, pattern).Success);
foreach (string file in matches)
{
Console.WriteLine(file);
fileName = System.IO.Path.GetFileName(file);
Console.WriteLine(fileName);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(file, destFile, true);
}
上記のプログラムは、単一のパターンでうまく機能します。
上記のプログラムを使用して、一致するパターンを持つディレクトリ内のファイルを検索していますが、私の場合は複数のパターンがあるため、複数のパターンをstring pattern
配列として変数に渡す必要がありますが、どのように操作できるかわかりませんRegex.Matchのこれらのパターン。
誰か助けてもらえますか?