2016-10-19 9 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

あなたのコードはワーク私のために完全にうまくいった...それはすべてのディレクトリとサブディレクトリをコピーした。一度メソッドを呼び出す際にパスを確認してください。 – A3006

+0

コピーを妨げるこの例外があると思います IOException:Win32 IOが返されました。 –

答えて

1

私はあなたのコードが正しい

、Windowsのシステムエラー112がディスクに十分な空き容量

+1

同じ問題だが、例外があるIOException:Win32 IOが返された。 –

+1

通常、Windowsシステムのエラー112は、ディスクに十分な空きがないことを意味する。 – cristallo

+0

Love u boyが適切な時間に来る。どこでそれを –

関連する問題