1. 程式人生 > >c#拷貝整個文件夾到指定文件夾下(非遞歸)

c#拷貝整個文件夾到指定文件夾下(非遞歸)

string 遞歸 creat all directory 指定 ted each getdir

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

c#拷貝整個文件夾到指定文件夾下(非遞歸)