文件批量替换

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;
                }
            }
        }
    }

 

posted @ 2017-10-13 12:02  DR19  阅读(101)  评论(0编辑  收藏  举报