C# 复制目录及其下文件

        public static void CopyDirectory(string sourceDirPath, string saveDirPath)
        {                         
            try
            {
                if (!Directory.Exists(sourceDirPath))
                {
                    Console.WriteLine("源目录不存在,请核对!");
                }

                if (!Directory.Exists(saveDirPath))
                {
                    Directory.CreateDirectory(saveDirPath);
                }
                string[] files = Directory.GetFiles(sourceDirPath);

                foreach (string file in files)
                {
                    string pFilePath = saveDirPath + @"\" + Path.GetFileName(file);
                    if (File.Exists(pFilePath))
                        continue;
                    File.Copy(file, pFilePath, true);
                }

                string[] dirs = Directory.GetDirectories(sourceDirPath);
                foreach (string dir in dirs)
                {
                    CopyDirectory(dir, saveDirPath + @"\" + Path.GetFileName(dir));
                }
            }
            catch (Exception)
            {

            }
        }

参考:https://blog.csdn.net/jhoneyan/article/details/52689146

C# 复制目录及其下文件

上一篇:Linux的50个基本命令


下一篇:Windows Azure Virtual Machine (39) 清除Linux挖矿病毒