c#程式片段,替換所有同名檔案
阿新 • • 發佈:2019-02-18
class Program { static void Main(string[] args) { try { replacefile rf = new replacefile(); rf.doReplace(@"F:\c1"); rf.doReplace(@"F:\c2"); rf.doReplace(@"F:\c3"); Console.WriteLine("替換完成!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } public class replacefile { public string sourceFilejs = @"F:\frmleftdown.js";//原始檔 public string sourceFilexml = @"F:\frmleftdown.xml";//原始檔 public void doReplace(string parentPath) { string[] files = Directory.GetFiles(parentPath); foreach (string f in files) { if (f=="frmleftdown.js") File.Copy(sourceFilejs, f, true);//替換目錄下所有的同名檔案 if (f=="frmleftdown.xml") File.Copy(sourceFilexml, f, true); } string[] subdirs = Directory.GetDirectories(parentPath); foreach (string subdir in subdirs) { doReplace(subdir); } } }