版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
static public bool CopyFolderContents(string SourcePath, string DestinationPath, string ignoreWord = "")
{
try
{
if (Directory.Exists(SourcePath))
{
if (Directory.Exists(DestinationPath) == false)
{
Directory.CreateDirectory(DestinationPath);
}
foreach (string files in Directory.GetFiles(SourcePath))
{
if (!string.IsNullOrEmpty(ignoreWord) && files.ToLower().Contains(ignoreWord.ToLower()) == true)
{
Debug.Log("Do Not Copy File. (Included Ignoreword) : " + SourcePath);
continue;
}
FileInfo fileInfo = new FileInfo(files);
fileInfo.CopyTo(string.Format("{0}/{1}", DestinationPath, fileInfo.Name), true);
}
foreach (string drs in Directory.GetDirectories(SourcePath))
{
if (!string.IsNullOrEmpty(ignoreWord) && drs.ToLower().Contains(ignoreWord.ToLower()) == true)
{
Debug.Log("Do Not Dir (Included Ignoreword) : " + SourcePath);
continue;
}
DirectoryInfo directoryInfo = new DirectoryInfo(drs);
if (CopyFolderContents(drs, DestinationPath + directoryInfo.Name) == false)
{
return false;
}
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}