Copying Directories

  • Thread starter Thread starter John Bowman
  • Start date Start date
J

John Bowman

I need to copy a directory to another locaiton. Is there some .Net
framework method I cannot find for copying a directory from 1 location to
another? I found the File.Copy(), but there does not seem to be a Directory
counterpart. Or do I have to code my own recrusion routine to do this?

TIA,
 
John,

There is nothing in the framework to support this outright. You can
iterate through all the directories and sub directories in the directory,
and copy the items yourself.

Also, you might want to try the SHFileOperation API function. It will
allow you to copy a directory from one location to another. You will have
to call it through the P/Invoke layer.

Hope this helps.
 
John Bowman" < said:
I need to copy a directory to another locaiton. Is there some .Net
framework method I cannot find for copying a directory from 1 location
to another? I found the File.Copy(), but there does not seem to be a
Directory counterpart. Or do I have to code my own recrusion routine
to do this?

This is off the top of my head, but it used to be that you could use the
Rename()-type functions to move directories... But it only worked if you
moved directories or files within the same drive.

Otherwise, just recreate the destination directory and loop to copy each
file.
 
garbriel & nicholas,

Thanks for the help. I guessed I was going to have to code this up myself.

Cheers,

John
 
Back
Top