/// <summary> /// Receives <see cref="QuickIODiskInformation"/> of specifies share path /// </summary> /// <returns><see cref="QuickIODiskInformation"/></returns> /// <remarks>See http://support.microsoft.com/kb/231497</remarks> public static QuickIODiskInformation GetDiskInformation(String sharePath) { Contract.Requires(!String.IsNullOrWhiteSpace(sharePath)); Contract.Ensures(Contract.Result <QuickIODiskInformation>() != null); return(InternalQuickIO.GetDiskInformation(sharePath)); }
/// <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 (!InternalQuickIO.CopyFile(source, target, out win32Error, overwrite)) { Win32ErrorCodes.NativeExceptionMapping(!Exists(source) ? target : target, win32Error); } }
/// <summary> /// Moves a specified file to a new location, providing the option to give a new file name. /// </summary> /// <param name="sourceFileName">The name of the file to move. </param> /// <param name="destinationFileName">The new path for the file. Parent directory must exist.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx</remarks> public static void Move(string sourceFileName, string destinationFileName) { Contract.Requires(!String.IsNullOrWhiteSpace(sourceFileName)); Contract.Requires(!String.IsNullOrWhiteSpace(destinationFileName)); InternalQuickIO.MoveFile(sourceFileName, destinationFileName); }
/// <summary> /// Moves a file, providing the option to give a new file name. /// </summary> /// <param name="sourceFileInfo">The file to move.</param> /// <param name="destinationFolder">Target directory to move the file.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx</remarks> public static void Move(QuickIOPathInfo sourceFileInfo, QuickIODirectoryInfo destinationFolder) { Contract.Requires(sourceFileInfo != null); Contract.Requires(destinationFolder != null); InternalQuickIO.MoveFile(sourceFileInfo.FullNameUnc, Path.Combine(destinationFolder.FullNameUnc, sourceFileInfo.Name)); }
/// <summary> /// Returns <see cref="QuickIODiskInformation"/> of this instance. /// </summary> /// <returns><see cref="QuickIODiskInformation"/></returns> /// <remarks>Only supported for <see cref="QuickIOShareType.Disk"/></remarks> /// <exception cref="UnsupportedShareTypeException">Metadata not supported for this Sharetype. Only available for <see cref="QuickIOShareType.Disk"/></exception> public QuickIODiskInformation GetDiskInformation() { Contract.Requires(!String.IsNullOrWhiteSpace(FullName)); Contract.Ensures(Contract.Result <QuickIODiskInformation>() != null); if (this.ShareType != QuickIOShareType.Disk) { throw new UnsupportedShareTypeException("Metadata not supported for this Sharetype", this.FullName); } return(InternalQuickIO.GetDiskInformation(this.FullName)); }
private static bool InternalDirectoryExists(string uncPath) { int win32Error; var attrs = InternalQuickIO.SafeGetAttributes(uncPath, out win32Error); if (Equals(attrs, 0xffffffff)) { return(false); } if (InternalHelpers.ContainsFileAttribute(FileAttributes.Directory, ( FileAttributes )attrs)) { return(true); } throw new UnmatchedFileSystemEntryTypeException(QuickIOFileSystemEntryType.Directory, QuickIOFileSystemEntryType.File, uncPath); }
/// <summary> /// Enumerate shares of specific machine. If no machine is specified, local machine is used /// </summary> /// <returns>Collection of <see cref="QuickIOShareInfo"/></returns> public static IEnumerable <QuickIOShareInfo> EnumerateShares(String machineName = null, QuickIOShareApiReadLevel level = QuickIOShareApiReadLevel.Admin) { Contract.Ensures(Contract.Result <IEnumerable <QuickIOShareInfo> >() != null); Type shareType = (level == QuickIOShareApiReadLevel.Admin) ? typeof(Win32ApiShareInfoAdmin) : typeof(Win32ApiShareInfoNormal); switch (level) { case QuickIOShareApiReadLevel.Admin: return(InternalQuickIO.EnumerateShares <Win32ApiShareInfoAdmin>(QuickIOShareApiReadLevel.Admin, machineName)); case QuickIOShareApiReadLevel.Normal: return(InternalQuickIO.EnumerateShares <Win32ApiShareInfoNormal>(QuickIOShareApiReadLevel.Normal, machineName)); default: throw new NotSupportedException($"Unsupported level '{level}'"); } }
/// <summary> /// Deletes the specified directory and, if indicated, any subdirectories and files in the directory. /// </summary> /// <param name="info">The name of the directory to remove. </param> /// <param name="recursive">true to remove directories, subdirectories, and files in path; otherwise, false. </param> /// <remarks>http://msdn.microsoft.com/en-us/library/fxeahc5f(v=vs.110).aspx</remarks> /// <exception cref="PathNotFoundException">One or more intermediate directories do not exist; this function will only create the final directory in the path.</exception> /// <exception cref="DirectoryNotEmptyException">The directory is not empty.</exception> /// <example> /// Creates directory structure /// <code> /// public static void Create_With_StringPath_Example() /// { /// QuickIOPathInfo pathInfo = new QuickIOPathInfo( @"C:\temp\QuickIOTest\sub\folder\tree" ); /// /// // Deletes directory C:\temp\QuickIOTest\sub\folder\tree and subfolders and files /// QuickIODirectory.Delete( pathInfo, recursive: true ); /// } /// </code> /// </example> /// <example> /// Shows how to handle sample exception if directory is not empty /// <code> /// public static void Create_With_StringPath_Example() /// { /// QuickIOPathInfo pathInfo = new QuickIOPathInfo( @"C:\temp\QuickIOTest\sub\folder\tree" ); /// /// try /// { /// QuickIODirectory.Delete( pathInfo, recursive: false ); /// } /// catch ( DirectoryNotEmptyException directoryNotEmptyException ) /// { /// // Directoy is not empty /// } /// } /// </code> /// </example> public static void Delete(QuickIOPathInfo info, bool recursive = false) { InternalQuickIO.DeleteDirectory(info.FullNameUnc, recursive); }
/// <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)); InternalQuickIO.SetAttributes(path, attributes); }
/// <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) { InternalQuickIO.SetLastWriteTimeUtc(new QuickIOPathInfo(path), lastWriteTimeUtc); }
/// <summary> /// Defines the time at which the file or directory was created (UTC) /// </summary> /// <param name="info">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(QuickIOFileInfo info, DateTime creationTimeUtc) { InternalQuickIO.SetCreationTimeUtc(info.PathInfo, creationTimeUtc); }
/// <summary> /// Sets the dates and times of given directory or file. /// </summary> /// <param name="info">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(QuickIOFileInfo info, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc) { InternalQuickIO.SetAllFileTimes(info.PathInfo, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc); }
/// <summary> /// Creates a new file. /// </summary> /// <param name="fullName">The path to the file. </param> /// <param name="fileAccess"><see cref="FileAccess"/> - default <see cref="FileAccess.Write"/></param> /// <param name="fileShare"><see cref="FileShare "/> - default <see cref="FileShare.None"/></param> /// <param name="fileMode"><see cref="FileMode"/> - default <see cref="FileMode.Create"/></param> /// <param name="fileAttributes"><see cref="FileAttributes"/> - default 0 (none)</param> /// <exception cref="PathAlreadyExistsException">The specified path already exists.</exception> /// <exception cref="PathNotFoundException">One or more intermediate directories do not exist; this function will only create the final directory in the path.</exception> public static void Create(String fullName, FileAccess fileAccess = FileAccess.Write, FileShare fileShare = FileShare.None, FileMode fileMode = FileMode.Create, FileAttributes fileAttributes = 0) { InternalQuickIO.CreateFile(fullName, fileAccess, fileShare, fileMode, fileAttributes); }
/// <summary> /// Checks whether the specified file exists. /// </summary> /// <param name="path">The path to check.</param> /// <returns><b>true</b> if the caller has the required permissions and path contains the name of an existing file; otherwise, <b>false</b></returns> /// <remarks>The original Exists method returns also false on null! http://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx</remarks> /// <exception cref="UnmatchedFileSystemEntryTypeException">Searched for file but found folder.</exception> /// <exception cref="InvalidPathException">Path is invalid.</exception> public static bool Exists(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); return(InternalQuickIO.FileExists(path)); }
/// <summary> /// Deletes the file. /// </summary> /// <param name="path">The fullname of the file to be deleted.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.delete(v=vs.110).aspx</remarks> /// <exception cref="FileNotFoundException">File does not exist.</exception> public static void Delete(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); InternalQuickIO.DeleteFile(path); }
/// <summary> /// Creates the path information container /// </summary> /// <param name="fullpath">Full path to the file or directory (regular or unc)</param> internal QuickIOPathInfo(String fullpath) : this(fullpath, InternalQuickIO.GetFindDataFromPath(fullpath)) { Contract.Requires(!String.IsNullOrWhiteSpace(fullpath)); }
/// <summary> /// Checks if path exists /// </summary> /// <param name="path">Path to check</param> /// <returns>True on exists</returns> public static Boolean Exists( String path ) { return InternalQuickIO.Exists( path ); }
/// <summary> /// Creates a new directory. If <paramref name="recursive"/> is false, the parent directory must exist. /// </summary> /// <param name="path">The directory.</param> /// <param name="recursive">If <paramref name="recursive"/> is false, the parent directory must exist.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/54a0at6s(v=vs.110).aspx</remarks> /// <exception cref="PathAlreadyExistsException">The specified path already exists.</exception> /// <exception cref="PathNotFoundException">One or more intermediate directories do not exist; this function will only create the final directory in the path.</exception> /// <example> /// Creates directory structure /// <code> /// public static void Create_With_PathInfo_Example( ); /// { /// QuickIOPathInfo pathInfo = new QuickIOPathInfo( @"C:\temp\QuickIOTest\sub\folder\tree" ); /// /// // Creates directory C:\temp\QuickIOTest\sub\folder\tree and all not existing parent folders /// QuickIODirectory.Create( pathInfo, recursive: true ); /// } /// </code> /// </example> /// <example> /// Shows how to handle sample exception if parent directory does not exist. /// <code> /// public static void Create_With_StringPath_Example() /// { /// QuickIOPathInfo pathInfo = new QuickIOPathInfo( @"C:\temp\QuickIOTest\sub\folder\tree" ); /// /// try /// { /// QuickIODirectory.Create( pathInfo, recursive: false ); /// } /// catch ( PathNotFoundException pathNotFoundException ) /// { /// // Parent directory does not exist. /// } /// } /// </code> /// </example> public static void Create(QuickIOPathInfo path, bool recursive = false) { Contract.Requires(path != null); InternalQuickIO.CreateDirectory(path.FullNameUnc, recursive); }
/// <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) { InternalQuickIO.SetAllFileTimes(new QuickIOPathInfo(path), creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc); }
/// <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 FileAttributes SetAttributes(string path, FileAttributes attributes) { return(InternalQuickIO.SetAttributes(path, attributes)); }
/// <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) { InternalQuickIO.SetCreationTimeUtc(new QuickIOPathInfo(path), creationTimeUtc); }
/// <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(InternalQuickIO.GetAttributes(path)); }
/// <summary> /// Defines the time at which the file or directory was last accessed (UTC) /// </summary> /// <param name="info">Affected file or directory</param> /// <param name="lastAccessTimeUtc">The time that is to be used (UTC)</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setlastaccesstimeutc(v=vs.110).aspx</remarks> public static void SetLastAccessTimeUtc(QuickIOPathInfo info, DateTime lastAccessTimeUtc) { InternalQuickIO.SetLastAccessTimeUtc(info, lastAccessTimeUtc); }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the directory or file. /// </summary> /// <param name="info">A directory or file. </param> /// <returns>The <see cref="FileAttributes"/> of the directory or file.</returns> public static FileAttributes GetAttributes(QuickIOPathInfo info) { return(InternalQuickIO.GetAttributes(info.FullNameUnc)); }
/// <summary> /// Defines the time at which the file or directory was last written (UTC) /// </summary> /// <param name="info">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(QuickIOFileInfo info, DateTime lastWriteTimeUtc) { InternalQuickIO.SetLastWriteTimeUtc(info.PathInfo, lastWriteTimeUtc); }
/// <summary> /// Adds the specified attribute to file or directory /// </summary> /// <param name="info">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(QuickIOPathInfo info, FileAttributes attribute) { return(InternalQuickIO.AddAttribute(info.FullNameUnc, attribute)); }
/// <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)); return(InternalQuickIO.AddAttribute(path, attribute)); }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the directory or file. /// </summary> /// <param name="info">A 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(QuickIOPathInfo info, FileAttributes attributes) { Contract.Requires(info != null); InternalQuickIO.SetAttributes(info.FullNameUnc, 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) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); return(InternalQuickIO.GetAttributes(path)); }
/// <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) { return(InternalQuickIO.RemoveAttribute(path, attribute)); }