文件批量替换
protected Dictionary<string, string> list = new Dictionary<string, string>(); protected void Page_Load(object sender, EventArgs e) { Dictionary<string, string> dicname = new Dictionary<string, string>(); string strpath = Server.MapPath("~/sipo/bak/"); DirectoryInfo Dir = new DirectoryInfo(strpath); foreach (FileInfo f in Dir.GetFiles("*.*", SearchOption.TopDirectoryOnly)) //查找文件 { foreach(var item in dicname) { if (f.ToString().StartsWith(item.Key)) { list.Add(f.ToString(), f.ToString().Replace(item.Key,item.Value)); File.Copy(Dir + @"\" + f.ToString(), Dir + @"\" + f.ToString().Replace(item.Key, item.Value), true); break; } } } }