真爱无限的知识驿站

学习积累技术经验,提升自身能力

c#程序片段,替换所有同名文件

code:

 

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


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.7.3

Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号