欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c#拷贝整个文件夹到指定文件夹下(非递归)

程序员文章站 2024-03-09 10:08:53
...

c#拷贝整个文件夹到指定文件夹下(非递归)

    public static void CopyEntireDir(string sourcePath, string destPath) {
       //Now Create all of the directories
        foreach (string dirPath in Directory.GetDirectories(sourcePath, "*",
           SearchOption.AllDirectories))
            Directory.CreateDirectory(dirPath.Replace(sourcePath, destPath));

       //Copy all the files & Replaces any files with the same name
        foreach (string newPath in Directory.GetFiles(sourcePath, "*.*",
           SearchOption.AllDirectories))
            File.Copy(newPath, newPath.Replace(sourcePath, destPath), true);
    }