/// <summary> /// Copies an existing file. Overwrites an existing file if <paramref name="overwrite"/> is true /// </summary> /// <param name="source">The file to copy.</param> /// <param name="target">Target file</param> /// <param name="overwrite">true to overwrite existing files</param> /// <param name="createRecursive">Creates parent path if not exists. Decreases copy performance</param> /// <remarks>http://msdn.microsoft.com/en-us/library/c6cfw35a(v=vs.110).aspx</remarks> /// <exception cref="FileSystemIsBusyException">Filesystem is busy</exception> public static void Copy(string source, string target, Boolean overwrite = false, Boolean createRecursive = true) { Contract.Requires(!String.IsNullOrWhiteSpace(source)); Contract.Requires(!String.IsNullOrWhiteSpace(target)); if (String.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } if (String.IsNullOrWhiteSpace(target)) { throw new ArgumentNullException(nameof(target)); } if (createRecursive) { var targetDirectoryPath = QuickIOPath.GetDirectoryName(target); try { QuickIODirectory.Create(targetDirectoryPath, true); } catch (PathAlreadyExistsException) { // yay ignore this! } } int win32Error; if (!QuickIOEngine.CopyFile(source, target, out win32Error, overwrite)) { Win32ErrorCodes.NativeExceptionMapping(!Exists(source) ? target : target, win32Error); } }
/// <summary> /// Creates the path information container /// </summary> /// <param name="fullpath">Full path to the file or directory (regular or unc)</param> /// <param name="win32FindData">Win32 handle information</param> internal QuickIOPathInfo(string fullpath, Win32FindData win32FindData) { Contract.Requires(fullpath != null); //Changed to allow paths which do not exist: //Contract.Requires( win32FindData != null ); this.FindData = win32FindData; this.Name = QuickIOPath.GetName(fullpath); this.FullName = QuickIOPath.ToPathRegular(fullpath); this.FullNameUnc = QuickIOPath.ToPathUnc(fullpath); // TODO: this.Parent = QuickIOPath.GetDirectoryName(fullpath); this.Root = QuickIOPath.GetPathRoot(fullpath); this.IsRoot = QuickIOPath.IsRoot(fullpath); }