Created
October 2, 2019 23:16
-
-
Save kyrathasoft/70d2bd4bbd955cadbf5380bc6e0d77e0 to your computer and use it in GitHub Desktop.
A method that faithfully copies an entire directory structure to another directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static bool CopyTo(string targetDirectory, string destinationDirectory) | |
| { | |
| bool blnSuccess = false; | |
| try{ | |
| if(Directory.Exists(targetDirectory)){ | |
| foreach (string dirPath in Directory.GetDirectories(targetDirectory, "*", | |
| SearchOption.AllDirectories)){ | |
| Directory.CreateDirectory(dirPath.Replace(targetDirectory, destinationDirectory)); | |
| } | |
| //Copy all the files & Replaces any files with the same name | |
| foreach (string newPath in Directory.GetFiles(targetDirectory, "*.*", | |
| SearchOption.AllDirectories)){ | |
| File.Copy(newPath, newPath.Replace(targetDirectory, destinationDirectory), true); | |
| blnSuccess = true; | |
| } | |
| } | |
| }catch(Exception exCopyTo){ | |
| Console.WriteLine("Error in ioLibrary: " + exCopyTo.Message); | |
| } | |
| return blnSuccess; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment