码迷,mamicode.com
首页 > 其他好文 > 详细

文件夹复制

时间:2020-04-08 12:02:24      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:string   cat   each   vat   reac   文件   pat   existing   ring   

/// <summary>
/// 复制文件夹
/// </summary>
/// <param name="SourcePath">源路径</param>
/// <param name="DestinationPath">目标路径</param>
/// <param name="overwriteexisting">是否覆盖现有</param>
/// <returns></returns>
private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
{
bool ret = false;
try
{
SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

if (Directory.Exists(SourcePath))
{
if (Directory.Exists(DestinationPath) == false)
Directory.CreateDirectory(DestinationPath);

foreach (string fls in Directory.GetFiles(SourcePath))
{
FileInfo flinfo = new FileInfo(fls);
flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
}
foreach (string drs in Directory.GetDirectories(SourcePath))
{
DirectoryInfo drinfo = new DirectoryInfo(drs);
if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
ret = false;
}
}
ret = true;
}
catch (Exception ex)
{
ret = false;
}
return ret;
}

文件夹复制

标签:string   cat   each   vat   reac   文件   pat   existing   ring   

原文地址:https://www.cnblogs.com/wgj-blog/p/12658447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!