/// <summary> /// Removes the specified attribute from file or directory /// </summary> /// <param name="path">A directory or file. </param> /// <param name="attribute">Attribute to remove </param> /// <returns>true if removed. false if not exists in attributes</returns> public static bool RemoveAttribute(string path, FileAttributes attribute) { FileAttributes updatedAttributes; bool result = QuickIOEngine.TryRemoveAttribute(QuickIOPath.ToPathUnc(path), attribute, out updatedAttributes); return(result); }
/// <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> /// Converts regular path to unc path /// </summary> /// <exception cref="InvalidOperationException">If path is invalid or cannot be identified</exception> public static string ToPathUnc(string path) { Contract.Requires(!String.IsNullOrEmpty(path)); // give origin if already unc if (IsShareUnc(path) || IsLocalUnc(path)) { // already unc return(path); } // convert to share if (IsShareRegular(path)) { return(QuickIOPath.ToSharePathUnc(path)); } // convert to local if (IsLocalRegular(path)) { return(QuickIOPath.ToLocalPathUnc(path)); } // it is already a regular path // or invalid. but will not be checked here return(path); }
/// <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> /// Adds the specified attribute to file or directory /// </summary> /// <param name="path">A directory or file. </param> /// <param name="attribute">Attribute to add </param> /// <returns>true if added. false if already exists in attributes</returns> public static bool AddAttribute(string path, FileAttributes attribute) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); FileAttributes updatedAttributes; bool result = QuickIOEngine.TryAddAttribute(QuickIOPath.ToPathUnc(path), attribute, out updatedAttributes); return(result); }
internal QuickIOFileSystemMetadataBase(string fullPath, Win32FindData win32FindData) { Contract.Requires(!String.IsNullOrWhiteSpace(fullPath)); Contract.Requires(win32FindData != null); FindData = win32FindData; FullNameUnc = QuickIOPath.ToPathUnc(fullPath); FullName = QuickIOPath.ToPathRegular(fullPath); this.LastWriteTimeUtc = win32FindData.GetLastWriteTimeUtc(); this.LastAccessTimeUtc = win32FindData.GetLastAccessTimeUtc(); this.CreationTimeUtc = win32FindData.GetCreationTimeUtc(); Name = win32FindData.cFileName; Attributes = win32FindData.dwFileAttributes; }
/// <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); }
/// <summary> /// Create new instance of <see cref="QuickIODirectoryInfo"/> /// </summary> public QuickIODirectoryInfo(String path) : this(new QuickIOPathInfo(QuickIOPath.GetFullPath(path))) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the directory or file. /// </summary> /// <param name="path">The path to the directory or file. </param> /// <returns>The <see cref="FileAttributes"/> of the directory or file.</returns> public static FileAttributes GetAttributes(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); return(QuickIOEngine.GetAttributes(QuickIOPath.ToPathUnc(path))); }
/// <summary> /// Defines the time at which the file or directory was last written (UTC) /// </summary> /// <param name="path">Affected file or directory</param> /// <param name="lastWriteTimeUtc">The time that is to be used (UTC)</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setlastwritetimeutc(v=vs.110).aspx</remarks> public static void SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc) { QuickIOEngine.SetLastWriteTimeUtc(QuickIOPath.ToPathUnc(path), lastWriteTimeUtc); }
/// <summary> /// Defines the time at which the file or directory was last accessed /// </summary> /// <param name="path">Affected file or directory</param> /// <param name="lastAccessTime">The time that is to be used</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setcreationtime(v=vs.110).aspx</remarks> public static void SetLastAccessTime(String path, DateTime lastAccessTime) { QuickIOEngine.SetLastAccessTimeUtc(QuickIOPath.ToPathUnc(path), lastAccessTime.ToUniversalTime( )); }
/// <summary> /// Defines the time at which the file or directory was created (UTC) /// </summary> /// <param name="path">Affected file or directory</param> /// <param name="creationTimeUtc">The time that is to be used (UTC)</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setcreationtimeutc(v=vs.110).aspx</remarks> public static void SetCreationTimeUtc(String path, DateTime creationTimeUtc) { QuickIOEngine.SetCreationTimeUtc(QuickIOPath.ToPathUnc(path), creationTimeUtc); }
/// <summary> /// Defines the time at which the file or directory was created /// </summary> /// <param name="path">Affected file or directory</param> /// <param name="creationTime">The time that is to be used</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setcreationtime(v=vs.110).aspx</remarks> public static void SetCreationTime(String path, DateTime creationTime) { QuickIOEngine.SetCreationTimeUtc(QuickIOPath.ToPathUnc(path), creationTime.ToUniversalTime( )); }
/// <summary> /// Sets the dates and times of given directory or file. /// </summary> /// <param name="path">Affected file or directory</param> /// <param name="creationTimeUtc">The time that is to be used (UTC)</param> /// <param name="lastAccessTimeUtc">The time that is to be used (UTC)</param> /// <param name="lastWriteTimeUtc">The time that is to be used (UTC)</param> public static void SetAllFileTimesUtc(String path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc) { QuickIOEngine.SetAllFileTimes(QuickIOPath.ToPathUnc(path), creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc); }
/// <summary> /// Sets the time the file was created. /// </summary> /// <param name="path">Affected file or directory</param> /// <param name="creationTime">The time that is to be used</param> /// <param name="lastAccessTime">The time that is to be used</param> /// <param name="lastWriteTime">The time that is to be used</param> public static void SetAllFileTimes(String path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime) { QuickIOEngine.SetAllFileTimes(QuickIOPath.ToPathUnc(path), creationTime.ToUniversalTime( ), lastAccessTime.ToUniversalTime( ), lastWriteTime.ToUniversalTime( )); }
/// <summary> /// Create new instance of <see cref="QuickIOFileInfo"/> /// </summary> public QuickIOFileInfo(String path) : this(new QuickIOPathInfo(QuickIOPath.GetFullPath(path))) { }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the directory or file. /// </summary> /// <param name="path">The path to the directory or file. </param> /// <param name="attributes">New attributes to set.</param> /// <returns>The <see cref="FileAttributes"/> of the directory or file.</returns> public static void SetAttributes(string path, FileAttributes attributes) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); QuickIOEngine.SetAttributes(QuickIOPath.ToPathUnc(path), attributes); }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the directory or file. /// </summary> /// <param name="path">The path to the directory or file. </param> /// <returns>The <see cref="FileAttributes"/> of the directory or file.</returns> public static FileAttributes GetAttributes(string path) { return(QuickIOEngine.GetAttributes(QuickIOPath.ToPathUnc(path))); }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the directory or file. /// </summary> /// <param name="path">The path to the directory or file. </param> /// <param name="attributes">New attributes to set.</param> /// <returns>The <see cref="FileAttributes"/> of the directory or file.</returns> public static void SetAttributes(string path, FileAttributes attributes) { QuickIOEngine.SetAttributes(QuickIOPath.ToPathUnc(path), attributes); }
/// <summary> /// Returns <see cref="Path"/> in regular. /// </summary> /// <returns></returns> public String GetPathRegular() { return(QuickIOPath.ToPathRegular(Path)); }
/// <summary> /// Returns <see cref="Path"/> in unc. /// </summary> /// <returns></returns> public String GetPathUnc() { return(QuickIOPath.ToPathUnc(Path)); }