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);
}
我上面的程序運行良好,只有一個模式。在目錄c#中查找匹配模式的文件?
我正在使用上面的程序來查找與匹配模式的目錄中的文件,但在我的情況下,我有多個模式,所以我需要在string pattern
變量中傳遞多個模式作爲數組,但我沒有想法如何我可以在Regex.Match中操縱這些模式。
任何人都可以幫助我嗎?
完美的傢伙,thankss! –