using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
public class Main{
public static void Copy(string SourcePath, string TargetPath){
List<string> directories = new List<string>();
string tmpDestination;
directories.Add(SourcePath);
while (directories.Count > 0)
{
string directory = directories[0];
tmpDestination = directory.Replace(SourcePath, "");
if (tmpDestination.Length >= 1 && tmpDestination.Substring(0, 1) == "\\")
{
tmpDestination = tmpDestination.Substring(1);
}
tmpDestination = Path.Combine(TargetPath, tmpDestination);
Directory.CreateDirectory(tmpDestination);
foreach (string file in Directory.GetFiles(directory))
{
FileInfo theFile = new FileInfo(file);
File.Copy(file, Path.Combine(tmpDestination, theFile.Name));
}
foreach (string tmpdir in Directory.GetDirectories(directory))
{
directories.Add(tmpdir);
}
directories.RemoveAt(0);
}
}
}
|