using System;
using System.IO;
namespace recursivecopy
{
class Program
{
static void Main(string[] args)
{
RecursiveCopyFolder(@"C:\All", @"C:\copied");
Console.ReadLine();
}
static public void RecursiveCopyFolder(string copyFromFolder, string copyToFolder)
{
if (!Directory.Exists(copyToFolder))
Directory.CreateDirectory(copyToFolder);
string[] files = Directory.GetFiles(copyFromFolder);
foreach (string file in files)
{
string fileNameToCopy = Path.GetFileName(file);
string dest = Path.Combine(copyToFolder, fileNameToCopy);
File.Copy(file, dest);
Console.WriteLine(file);
}
string[] allFolders = Directory.GetDirectories(copyFromFolder);
foreach (string folder in allFolders)
{
string fileNameToCopy = Path.GetFileName(folder);
string dest = Path.Combine(copyToFolder, fileNameToCopy);
RecursiveCopyFolder(folder, dest);
Console.WriteLine(folder);
}
}
}
}
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......