Copy Folders in C# using System.IO

后端 未结 9 872
傲寒
傲寒 2020-12-10 03:20

I need to Copy folder C:\\FromFolder to C:\\ToFolder

Below is code that will CUT my FromFolder and then will create my ToFolder. So my FromFolder will be gone and al

9条回答
  •  执念已碎
    2020-12-10 04:06

    You'll need to create a new directory from scratch then loop through all the files in the source directory and copy them over.

    string[] files = Directory.GetFiles(GlobalVariables.mstrReadsWellinPath);
    foreach(string s in files)
    {
            fileName=Path.GetFileName(s);
            destFile = Path.Combine(DestinationPath, fileName);
            File.Copy(s, destFile);
    }
    

    I leave creating the destination directory to you :-)

提交回复
热议问题