/// <summary> /// Copies an existing file. Overwrites an existing file if <paramref name="overwrite"/> is true /// </summary> /// <param name="sourceFileName">The file to copy.</param> /// <param name="targetDirectory">Target directory</param> /// <param name="newFileName">New File name. Null or empty to use <paramref name="sourceFileName"/>'s name</param> /// <param name="overwrite">true to overwrite existing file</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 CopyToDirectory(string sourceFileName, string targetDirectory, String newFileName = null, Boolean overwrite = false) { Contract.Requires(!String.IsNullOrWhiteSpace(sourceFileName)); Contract.Requires(!String.IsNullOrWhiteSpace(targetDirectory)); if (String.IsNullOrWhiteSpace(sourceFileName)) { throw new ArgumentNullException(nameof(sourceFileName)); } if (String.IsNullOrWhiteSpace(targetDirectory)) { throw new ArgumentNullException(nameof(targetDirectory)); } // determine filename string targetFileName; if (!String.IsNullOrWhiteSpace(newFileName)) { // TODO: Check for invalid chars targetFileName = newFileName; } else { targetFileName = QuickIOPath.GetName(sourceFileName); } Copy(sourceFileName, QuickIOPath.Combine(targetDirectory, targetFileName), overwrite); }
/// <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); }