//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System.IO; namespace BansheeEngine { /** @addtogroup Utility * @{ */ /// /// Contains various methods that provide handling for directories not provided by System.Directory type. /// public static class DirectoryEx { /// /// Moves a directory from one path to another, while creating any parent directories if they don't already exist. /// /// Path to the directory to move. /// New location and/or name of the directory. public static void Move(string source, string destination) { string destParent = PathEx.GetParent(destination); if (!string.IsNullOrEmpty(destParent)) { if (!Directory.Exists(destParent)) Directory.CreateDirectory(destParent); } Directory.Move(source, destination); } /// /// Recursively copies a directory from one path to another, while creating any parent directories if they don't /// already exist. /// /// Path to the directory to copy. /// Path determining where the directory copy will be placed. public static void Copy(string source, string destination) { DirectoryInfo dir = new DirectoryInfo(source); DirectoryInfo[] dirs = dir.GetDirectories(); if (!dir.Exists) { throw new DirectoryNotFoundException( "Source directory does not exist or could not be found: " + source); } if (!Directory.Exists(destination)) Directory.CreateDirectory(destination); FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { string temppath = Path.Combine(destination, file.Name); file.CopyTo(temppath, false); } foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(destination, subdir.Name); Copy(subdir.FullName, temppath); } } } /** @} */ }