public static void CopyFolder(string srcFolder, string desFolder)
{
if (!File.Exists(srcFolder) && !Directory.Exists(srcFolder))
{
Debug.LogError($"拷贝文件失败不存在 源目录:{srcFolder}");
return;
}
if ((new DirectoryInfo(srcFolder)).FullName.CompareTo((new DirectoryInfo(desFolder).FullName)) == 0)
{
Debug.LogError($"拷贝源目录与目标目录相同:{srcFolder}, {desFolder}");
return;
}
var allFile = Directory.GetFiles(srcFolder, "*", SearchOption.AllDirectories);
for (int i = 0; i < allFile.Length; i++)
{
var desFile = allFile[i].Replace(srcFolder, desFolder);
//Debug.Log($"拷贝覆盖文件:{allFile[i]} -> {desFile}");
if (File.Exists(desFile))
{
FileUtil.ReplaceFile(allFile[i], desFile);
}
else
{
var folder = Path.GetDirectoryName(desFile);
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
FileUtil.CopyFileOrDirectory(allFile[i], desFile);
}
}
Debug.Log($"拷贝完成:{srcFolder} -> {desFolder}");
}