How to copy a directory? 
Author Message
 How to copy a directory?

Just copy a directory from one path to another path.I
can't find this method in .net framework. Anyone knows?
Thanks in advance.


Thu, 30 Dec 2004 02:39:21 GMT  
 How to copy a directory?


Quote:
> Just copy a directory from one path to another path.I
> can't find this method in .net framework. Anyone knows?
> Thanks in advance.

There doesn't appear to be a way to do it with just one
call.

However you can just create a new directory, get a list
of the files from the old one and call copy on each one.

That's probably all the Directoy.Copy() method would do
anyhow.

You'd have to do it recursively, though, in case there
were any subdirectories.

-c



Thu, 30 Dec 2004 04:21:41 GMT  
 How to copy a directory?
Something like this:

  private void CopyDirectory(string sourceDirectoryName, string
targerDirectoryName)
  {
   Directory.CreateDirectory(targerDirectoryName);

   string[] files = Directory.GetFiles(sourceDirectoryName);

   foreach(string fileName in files)
    File.Copy(fileName, targerDirectoryName + Path.DirectorySeparatorChar +
Path.GetFileName(fileName));

   string[] directories = Directory.GetDirectories(sourceDirectoryName);

   foreach(string directory in directories)
    CopyDirectory(directory, targerDirectoryName +
Path.DirectorySeparatorChar + Path.GetFileName(directory));
  }

Working project: http://www.bowgett.com/Examples/files/CopyDir.zip

--
This posting is provided "AS IS" with no warranties, and confers no rights


Quote:
> Just copy a directory from one path to another path.I
> can't find this method in .net framework. Anyone knows?
> Thanks in advance.



Fri, 31 Dec 2004 07:30:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Trying to copy a directory

2. Moving/Copying whole directories as well as subdirectories

3. How to copy a directory structure

4. How to Copy a directory and it's contents?

5. How to Copy a directory and it's contents?

6. MFC or API to Delete Directory and Copy Directory

7. error: dependency cannot copied to run directory

8. still problems with Could not copy temporary files to the output directory

9. Recursice directory copy.

10. copy active directory user

11. how to copy files to build directory

12. Copy Directory

 

 
Powered by phpBB® Forum Software