2016-10-19 4 views
-4

SO post의 기능을 사용하여 폴더 내용을 다른 폴더에 복사하지만 하위 폴더와 해당 내용을 복사하지는 않습니다.하위 폴더가 복사되지 않았습니다

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); 
+4

가능한 복제의에 공간이 충분하지 의미 [C#에서 디렉터리의 전체 내용을 복사하는 가장 좋은 방법은] (http://stackoverflow.com/questions/58744/best-way-to-copy-the-entire-contents-of-a-directory-in-c - 샤프) – BartoszKP

+2

당신의 코드 worke 나를 위해 완벽하게 잘 ... 그것은 모든 디렉토리와 하위 디렉토리를 복사했습니다. 한 번 호출 방법의 경로를 확인해 주시겠습니까? – A3006

+0

복사를 방해하는이 예외가있는 것 같음 IOException : Win32 IO가 112를 반환했습니다. –

답변

1

내가 코드를 보이는 것에 동의 올바른

Windows 시스템 오류 (112)는 디스크

+1

동일한 문제가 있지만 예외가 발생했습니다 IOException : Win32 입출력 112 반환했습니다. –

+1

일반적으로 Windows 시스템 오류 112 디스크에 충분한 공간이 없다는 것을 의미합니다 – cristallo

+0

사랑하는 소년은 적절한 시간에 온다. 어디서 그걸 받아 들일 수 있도록 –

관련 문제