Click to See Complete Forum and Search --> : Copying Directories


Amrita
May 7th, 2003, 07:34 AM
I am wondering How can i copy, Directories containing Files and subdirectories from a CD to a desired location on my hardDrive programmatically?
any help anywhere

Sunil_R
May 7th, 2003, 07:57 AM
You can use MovefileEx API to move files from one location to another.

cheers
sunil

pareshgh
May 7th, 2003, 01:11 PM
if you want to copy a folder from another folder you can try following,

public static void CopyDirectory(String source, String destination) {
DirectoryInfo currentDirectory = new DirectoryInfo(source);
foreach (FileInfo file in currentDirectory.GetFiles()) {
File.Copy(file.FullName, Path.Combine(destination, file.Name));
}
foreach (DirectoryInfo directory in currentDirectory.GetDirectories()) {
String subDirectory = Path.Combine(destination, directory.Name);
Directory.CreateDirectory(subDirectory);
CopyDirectory(directory.FullName, subDirectory);
}
}

you will need to modify some stuff as per your need.

hope this helps
Paresh

pareshgh
May 7th, 2003, 01:12 PM
another sample,

FileInfo file = new FileInfo(fileName.Replace(source, destination));

if(overwrite) file.CopyTo(file.FullName, true);

actually no need to invoke platform commands,


-Paresh