Copier coller

Copier coller un répertoire en C# (Copy-Paste folder)

De Admin dans C#


 5/27/2015

Copier le contenu d'un répertoire en utilisant la récursivité :

private static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
   // Check if the target directory exists, if not, create it.
   if (Directory.Exists(target.FullName) == false)
   {
       Directory.CreateDirectory(target.FullName);
   }
   // Copy each file into the new directory.
   foreach (FileInfo fi in source.GetFiles())
   {
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
   }
   // Copy each subdirectory using recursion.
   foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
   {
       DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
       CopyAll(diSourceSubDir, nextTargetSubDir);
   }
}

Lire >>