子文件夹不被复制
本文关键字:复制 文件夹 | 更新日期: 2023-09-27 18:13:39
我正在使用此SO帖子的函数将文件夹内容复制到另一个文件夹,但它不复制子文件夹及其内容。
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
// If the source directory does not exist, throw an exception.
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory does not exist, create it.
if (!Directory.Exists(destDirName))
{
Debug.Log("Directory created.." + destDirName);
Directory.CreateDirectory(destDirName);
}
// Get the file contents of the directory to copy.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
// Create the path to the new copy of the file.
string temppath = Path.Combine(destDirName, file.Name);
// Copy the file.
file.CopyTo(temppath, false);
}
// If copySubDirs is true, copy the subdirectories.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
// Create the subdirectory.
string temppath = Path.Combine(destDirName, subdir.Name);
// Copy the subdirectories.
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
它的名字是这样的:
string destingationPath = startupFolder + @"'NetworkingDemoPlayerWithNetworkAwareShooting1_Data";
DirectoryCopy("NetworkingDemoPlayerWithNetworkAwareShooting1_Data", destingationPath, true);
我同意你的代码看起来是正确的
Windows系统错误112意味着磁盘上没有足够的空间