Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 子文件夹未被复制_C# - Fatal编程技术网

C# 子文件夹未被复制

C# 子文件夹未被复制,c#,C#,我正在使用此功能将文件夹内容复制到另一个文件夹中,但它不会复制子文件夹及其内容 private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) { DirectoryInfo dir = new DirectoryInfo(sourceDirName); DirectoryInfo[] dirs = dir.GetDirectories(); //

我正在使用此功能将文件夹内容复制到另一个文件夹中,但它不会复制子文件夹及其内容

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表示磁盘上没有足够的空间

您的代码的可能副本对我来说工作得很好。。。它复制了所有目录和子目录。您能检查一下调用方法的路径吗?我想这个异常会妨碍复制IOException:Win32 IO返回112。@Anand yes code是正确的,cristallo提到了存储问题。谢谢我的问题,但我得到了异常,它是说IOException:Win32 IO返回112。通常Windows系统错误112表示磁盘上没有足够的空间。请将此内容更新到您的代码中,以便我可以接受它。虽然我的代码也是有效的。无论如何,再次感谢您,但为什么我复制的应用程序没有运行。给我一个错误“C:\…player.exe不是有效的win32应用程序”,你能比较源文件和目标文件吗?二进制是相同的吗?