public static DirectoryCopy ( string sourceFolderName, string destinationFolderName, bool copySubFolders ) : void | ||
sourceFolderName | string | Name of the source dir. |
destinationFolderName | string | Name of the dest dir. |
copySubFolders | bool | if set to |
return | void |
/// <summary> /// Copies directories and files, eventually recursively. From MSDN. /// </summary> /// <param name="sourceFolderName">Name of the source dir.</param> /// <param name="destinationFolderName">Name of the dest dir.</param> /// <param name="copySubFolders">if set to <c>true</c> it will recursively copy files/folders.</param> public static void DirectoryCopy(string sourceFolderName, string destinationFolderName, bool copySubFolders) { // Get the subdirectories for the specified directory. DirectoryInfo sourceFolder = new DirectoryInfo(sourceFolderName); if (!sourceFolder.Exists) { throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceFolderName); } DirectoryInfo[] sourceFoldersToCopy = sourceFolder.GetDirectories(); // If the destination directory doesn't exist, create it. if (!Directory.Exists(destinationFolderName)) { Directory.CreateDirectory(destinationFolderName); } // Get the files in the directory and copy them to the new location. foreach (FileInfo file in sourceFolder.GetFiles()) { file.CopyTo(Path.Combine(destinationFolderName, file.Name), true); } if (copySubFolders) { foreach (DirectoryInfo subFolder in sourceFoldersToCopy) { Utils.DirectoryCopy(subFolder.FullName, Path.Combine(destinationFolderName, subFolder.Name), copySubFolders); } } }
internal void CopyThemeToDestination() { var sourceFolder = Path.Combine(this.ThemeFolder, "Destination"); if (!Directory.Exists(sourceFolder)) { Console.WriteLine("[WARNING] No theme content found! 'Destination' folder in theme folder '{0}' is missing.", this.ThemeFolder); return; } Utils.DirectoryCopy(sourceFolder, this.Destination, copySubFolders: true); }
internal void CopySourceFoldersToCopy() { var foldersToCopy = this.SourceFoldersToCopy; foreach (var folder in foldersToCopy) { if (string.IsNullOrWhiteSpace(folder)) { continue; } var sourceFolderName = Path.Combine(this.Source, folder); if (!Directory.Exists(sourceFolderName)) { continue; } var destinationFolderName = Path.Combine(this.Destination, folder); Console.WriteLine("... copying '{0}' to {1}", sourceFolderName, destinationFolderName); Utils.DirectoryCopy(sourceFolderName, destinationFolderName, copySubFolders: true); } }