标签:exist direct new 目标 存在 文件 tin nat com
/// <summary> /// 拷贝目录内容 /// </summary> /// <param name="source">源目录</param> /// <param name="destination">目的目录</param> /// <param name="copySubDirs">是否拷贝子目录</param> public static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination, bool copySubDirs) { if (!destination.Exists) { destination.Create(); //目标目录若不存在就创建 } FileInfo[] files = source.GetFiles(); foreach (FileInfo file in files) { file.CopyTo(Path.Combine(destination.FullName, file.Name), true); //复制目录中所有文件 } if (copySubDirs) { DirectoryInfo[] dirs = source.GetDirectories(); foreach (DirectoryInfo dir in dirs) { string destinationDir = Path.Combine(destination.FullName, dir.Name); CopyDirectory(dir, new DirectoryInfo(destinationDir), copySubDirs); //复制子目录 } } }
http://blog.sina.com.cn/s/blog_61e786780100iiud.html
标签:exist direct new 目标 存在 文件 tin nat com
原文地址:http://www.cnblogs.com/shy1766IT/p/7295720.html