Copying Directories

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,
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

gabriel

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.
 
J

John Bowman

garbriel & nicholas,

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

Cheers,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top