Copying a directory.

  • Thread starter Thread starter Russell Greenlaw
  • Start date Start date
R

Russell Greenlaw

All,

Maybe I am missing something but how do you Copy a directory? The
DirectoryInfo and Directory classes have methods to Delete, Move and Create
directories so why no method to Copy one?

Thanks.

RGG
 
Probably to keep from fooling you into thinking that a hypothetical
Directory.Copy would be anywhere near as efficient as any of the other
methods you mentioned. That's a pretty sucky reason, but it's all I can
think of.

Of course, to do a directory copy, all that's necessary is to write a
function like this:

function CopyDir(Directory d, string destPath) {
foreach (File f in d)
copy f to destPath
foreach (Directory c in d)
CopyDir(c, Path.Combine(destPath, c.Name));
}

Chris
 
Thanks Chris,

What is confusing is that the docs for the Directory class actually mentions
copying directories.

Thanks for the function

RGG
 
Back
Top