Copy Directory Recursive Internal - CSharp File IO

CSharp examples for File IO:Directory

Description

Copy Directory Recursive Internal

Demo Code


using System.Threading.Tasks;
using System.Linq;
using System.IO;/*  w w w . jav a2s.  c om*/
using System;

public class Main{
        private static void CopyDirectoryRecursiveInternal(DirectoryInfo source, string destination)
        {
            if (!Directory.Exists(destination)) Directory.CreateDirectory(destination);

            foreach (var file in source.GetFiles())
                file.CopyTo(Path.Combine(destination, file.Name));

            foreach (var directory in source.GetDirectories())
                CopyDirectoryRecursiveInternal(directory, Path.Combine(destination, directory.Name));
        }
}

Related Tutorials