Friday, September 17, 2010

Copy complete folder with respective folder hierarchy to another location

public class FileSystem{
// Copy directory structure recursively

public static void copyDirectory(string Src,string Dst){
String[] Files;

if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
Dst+=Path.DirectorySeparatorChar;
if(!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
Files=Directory.GetFileSystemEntries(Src);
foreach(string Element in Files){
// Sub directories

if(Directory.Exists(Element))
copyDirectory(Element,Dst+Path.GetFileName(Element));
// Files in directory

else
File.Copy(Element,Dst+Path.GetFileName(Element),true);
}
}

}

No comments:

Post a Comment

 
Locations of visitors to this page