Created
June 27, 2018 07:35
-
-
Save polarstars/b4e936393706ae5a233c99980d195343 to your computer and use it in GitHub Desktop.
拷贝目录及子目录内容 #C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void CopyDirectory(String sourcePath, String destinationPath) | |
{ | |
DirectoryInfo info = new DirectoryInfo(sourcePath); | |
Directory.CreateDirectory(destinationPath); | |
foreach (FileSystemInfo fsi in info.GetFileSystemInfos()) | |
{ | |
String destName = Path.Combine(destinationPath, fsi.Name); | |
if (fsi is System.IO.FileInfo) //如果是文件,复制文件 | |
File.Copy(fsi.FullName, destName); | |
else //如果是文件夹,新建文件夹,递归 | |
{ | |
Directory.CreateDirectory(destName); | |
CopyDirectory(fsi.FullName, destName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment