/// <summary> /// Writes the specified byte array. /// If the file already exists, it is overwritten. /// </summary> /// <param name="pathInfo">The file. </param> /// <param name="bytes">The bytes to write. </param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes(v=vs.110).aspx</remarks> public static void WriteAllBytes( QuickIOPathInfo pathInfo, IEnumerable<byte> bytes ) { Contract.Requires( pathInfo != null ); Contract.Requires( bytes != null ); WriteAllBytes( pathInfo.FullNameUnc, bytes.ToArray() ); }
/// <summary> /// Copies a directory and all contents /// </summary> /// <param name="source">Source directory</param> /// <param name="target">Target directory</param> /// <param name="overwrite">true to overwrite existing files</param> /// <param name="cancellationToken">Cancallation Token</param> public static void Copy( QuickIODirectoryInfo source, QuickIOPathInfo target, bool overwrite = false, CancellationToken cancellationToken = default( CancellationToken ) ) { Contract.Requires( source != null ); Contract.Requires( target != null ); throw new NotImplementedException(); }
/// <summary> /// Appends the specified string. /// If the file does not exist, it creates the file. /// </summary> /// <param name="pathInfo">The file to append the specified string to.</param> /// <param name="contents">The string to append to the file.</param> /// <param name="encoding">The character encoding.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/ms143356(v=vs.110).aspx</remarks> public static void AppendAllText(QuickIOPathInfo pathInfo, string contents, Encoding encoding) { Contract.Requires(pathInfo != null); Contract.Requires(contents != null); AppendAllText(pathInfo.FullNameUnc, contents, encoding); }
/// <summary> /// Appends lines by using the specified encoding. /// If the file does not exist, it creates the file. /// </summary> /// <param name="pathInfo">The file to append the lines to. The file is created if it doesn't exist.</param> /// <param name="contents">The lines to append.</param> /// <param name="encoding">The character encoding.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383356(v=vs.110).aspx</remarks> public static void AppendAllLines(QuickIOPathInfo pathInfo, IEnumerable <string> contents, Encoding encoding = null) { Contract.Requires(pathInfo != null); Contract.Requires(contents != null); AppendAllLines(pathInfo.FullNameUnc, contents, encoding); }
/// <summary> /// Copies a directory and all contents /// </summary> /// <param name="source">Source directory</param> /// <param name="target">Target directory</param> /// <param name="overwrite">true to overwrite existing files</param> /// <param name="cancellationToken">Cancallation Token</param> public static void Copy(QuickIODirectoryInfo source, QuickIOPathInfo target, bool overwrite = false, CancellationToken cancellationToken = default(CancellationToken)) { Contract.Requires(source != null); Contract.Requires(target != null); throw new NotImplementedException(); }
/// <summary> /// Appends the specified string. /// If the file does not exist, it creates the file. /// </summary> /// <param name="pathInfo">The file to append the specified string to.</param> /// <param name="contents">The string to append to the file.</param> /// <param name="encoding">The character encoding.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/ms143356(v=vs.110).aspx</remarks> public static void AppendAllText( QuickIOPathInfo pathInfo, string contents, Encoding encoding ) { Contract.Requires( pathInfo != null ); Contract.Requires( contents != null ); AppendAllText( pathInfo.FullNameUnc, contents, encoding ); }
/// <summary> /// Opens a <see cref="FileStream"/> /// </summary> /// <param name="pathInfo">The file to open. </param> /// <param name="mode"><see cref="FileMode"/> </param> /// <param name="access"><see cref="FileAccess"/></param> /// <param name="share"><see cref="FileShare"/></param> /// <returns><see cref="FileStream"/></returns> /// <remarks>http://msdn.microsoft.com/en-us/library/y973b725(v=vs.110).aspx</remarks> public static FileStream Open(QuickIOPathInfo pathInfo, FileMode mode, FileAccess access, FileShare share) { Contract.Requires(pathInfo != null); Contract.Ensures(Contract.Result <FileStream>() != null); return(OpenFileStream(pathInfo.FullNameUnc, access, mode, share)); }
/// <summary> /// Checks whether the path with the expected system entry type exists /// </summary> /// <param name="pathInfo">A file or a directory</param> /// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param> /// <returns></returns> /// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception> public static Boolean Exists( QuickIOPathInfo pathInfo, QuickIOFileSystemEntryType systemEntryType ) { switch ( systemEntryType ) { case QuickIOFileSystemEntryType.Directory: try { InternalQuickIO.LoadDirectoryFromPathInfo( pathInfo ); return true; } catch ( PathNotFoundException ) { return false; } case QuickIOFileSystemEntryType.File: try { InternalQuickIO.LoadFileFromPathInfo( pathInfo ); return true; } catch ( PathNotFoundException ) { return false; } default: throw new ArgumentException( "Unknown QuickIOFileSystemEntryType passed." ); } }
/// <summary> /// Writes the specified byte array. /// If the file already exists, it is overwritten. /// </summary> /// <param name="pathInfo">The file. </param> /// <param name="bytes">The bytes to write. </param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes(v=vs.110).aspx</remarks> public static void WriteAllBytes(QuickIOPathInfo pathInfo, IEnumerable <byte> bytes) { Contract.Requires(pathInfo != null); Contract.Requires(bytes != null); WriteAllBytes(pathInfo.FullNameUnc, bytes.ToArray()); }
/// <summary> /// File content hash calculation /// </summary> public static QuickIOHashResult CalculateHash( QuickIOPathInfo pathInfo, QuickIOHashImplementationType hashImplementationType ) { Contract.Requires( pathInfo != null ); switch( hashImplementationType ) { case QuickIOHashImplementationType.SHA1: return CalculateSha1Hash( pathInfo ); case QuickIOHashImplementationType.SHA256: return CalculateSha256Hash( pathInfo ); case QuickIOHashImplementationType.SHA384: return CalculateSha384Hash( pathInfo ); case QuickIOHashImplementationType.SHA512: return CalculateSha512Hash( pathInfo ); case QuickIOHashImplementationType.MD5: return CalculateMD5Hash( pathInfo ); default: throw new NotImplementedException( "Type " + hashImplementationType + " not implemented." ); } }
/// <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); QuickIOEngine.MoveFile(sourceFileInfo.FullNameUnc, Path.Combine(destinationFolder.FullNameUnc, sourceFileInfo.Name)); }
/// <summary> /// Appends lines by using the specified encoding. /// If the file does not exist, it creates the file. /// </summary> /// <param name="pathInfo">The file to append the lines to. The file is created if it doesn't exist.</param> /// <param name="contents">The lines to append.</param> /// <param name="encoding">The character encoding.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383356(v=vs.110).aspx</remarks> public static void AppendAllLines( QuickIOPathInfo pathInfo, IEnumerable<string> contents, Encoding encoding = null ) { Contract.Requires( pathInfo != null ); Contract.Requires( contents != null ); AppendAllLines( pathInfo.FullNameUnc, contents, encoding ); }
/// <summary> /// Copies a directory and all contents /// </summary> /// <param name="source">Source directory</param> /// <param name="target">Target directory</param> /// <param name="overwrite">true to overwrite existing files</param> public static void Copy( QuickIODirectoryInfo source, QuickIOPathInfo target, bool overwrite = false ) { Invariant.NotNull( source ); Invariant.NotNull( target ); var allContentUncPaths = EnumerateFileSystemEntryPaths( source, QuickIOPatternConstants.All, SearchOption.AllDirectories, QuickIOPathType.UNC ); foreach ( var entry in allContentUncPaths ) { string sourcePathUnc = entry.Key; var targetFullnameUnc = target.FullNameUnc + sourcePathUnc.Substring( source.FullNameUnc.Length ); switch ( entry.Value ) { case QuickIOFileSystemEntryType.Directory: { QuickIODirectory.Create( targetFullnameUnc, true ); } break; case QuickIOFileSystemEntryType.File: { QuickIOFile.Copy( sourcePathUnc, targetFullnameUnc, overwrite ); } break; } } }
/// <summary> /// Reads all text with the specified encoding. /// </summary> /// <param name="pathInfo">The file. </param> /// <param name="encoding">The encoding applied to the content. </param> /// <returns>A string represents the content.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/ms143369(v=vs.110).aspx</remarks> public static string ReadAllText(QuickIOPathInfo pathInfo, Encoding encoding) { using (var streamReader = new StreamReader(OpenRead(pathInfo.FullNameUnc), encoding)) { return(streamReader.ReadToEnd( )); } }
/// <summary> /// Receives <see cref="QuickIODirectoryMetadata"/> of current directory /// </summary> /// <returns><see cref="QuickIODirectoryMetadata"/></returns> public static QuickIODirectoryMetadata EnumerateDirectoryMetadata( QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { Contract.Requires( pathInfo != null ); Contract.Ensures( Contract.Result<QuickIODirectoryMetadata>() != null ); return EnumerateDirectoryMetadata( pathInfo.FullNameUnc, enumerateOptions ); }
/// <summary> /// Opens a <see cref="FileStream"/> /// </summary> /// <param name="pathInfo">The file to open. </param> /// <param name="mode"><see cref="FileMode"/> </param> /// <param name="access"><see cref="FileAccess"/></param> /// <param name="share"><see cref="FileShare"/></param> /// <returns><see cref="FileStream"/></returns> /// <remarks>http://msdn.microsoft.com/en-us/library/y973b725(v=vs.110).aspx</remarks> public static FileStream Open( QuickIOPathInfo pathInfo, FileMode mode, FileAccess access, FileShare share ) { Contract.Requires( pathInfo != null ); Contract.Ensures( Contract.Result<FileStream>() != null ); return OpenFileStream( pathInfo.FullNameUnc, access, mode, share ); }
/// <summary> /// Opens an existing file for reading. /// </summary> /// <param name="pathInfo">The file to be opened for reading. </param> /// <returns>A read-only <see cref="FileStream"/> on the specified path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.openread(v=vs.110).aspx</remarks> public static FileStream OpenRead( QuickIOPathInfo pathInfo ) { Contract.Requires( pathInfo != null ); Contract.Ensures( Contract.Result<StreamReader>() != null ); return OpenRead( pathInfo.FullNameUnc ); }
/// <summary> /// Opens an existing file for reading. /// </summary> /// <param name="pathInfo">The file to be opened for reading. </param> /// <returns>A read-only <see cref="FileStream"/> on the specified path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.openread(v=vs.110).aspx</remarks> public static FileStream OpenRead(QuickIOPathInfo pathInfo) { Contract.Requires(pathInfo != null); Contract.Ensures(Contract.Result <StreamReader>() != null); return(OpenRead(pathInfo.FullNameUnc)); }
/// <summary> /// Receives <see cref="QuickIODirectoryMetadata"/> of current directory /// </summary> /// <returns><see cref="QuickIODirectoryMetadata"/></returns> public static QuickIODirectoryMetadata EnumerateDirectoryMetadata(QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None) { Contract.Requires(pathInfo != null); Contract.Ensures(Contract.Result <QuickIODirectoryMetadata>() != null); return(EnumerateDirectoryMetadata(pathInfo.FullNameUnc, enumerateOptions)); }
/// <summary> /// Creates the folder information on the basis of the path and the handles /// </summary> /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param> /// <param name="win32FindData"><see cref="Win32FindData"/></param> internal QuickIODirectoryInfo( QuickIOPathInfo pathInfo, Win32FindData win32FindData ) : base(pathInfo, win32FindData) { if ( win32FindData != null ) { RetriveDateTimeInformation( win32FindData ); } }
/// <summary> /// File content hash calculation using MD5 /// </summary> /// <returns><see cref="QuickIOHashResult"/></returns> /// <example> /// <code> /// // Show human readable hash /// QuickIOHashResult hashResult = QuickIOFile.CalculateMD5Hash( "C:\temp\image.bin" ); /// Console.WriteLine("Hash: {0}", hashResult.Format( Encoding.UTF8, "x2" ); /// </code> /// </example> public static QuickIOHashResult CalculateMD5Hash( QuickIOPathInfo pathInfo ) { using ( var fs = OpenRead( pathInfo ) ) using ( var hashAlgorithm = new MD5CryptoServiceProvider( ) ) { return CalculateHash( hashAlgorithm, fs ); } }
/// <summary> /// Writes the specified byte array. /// If the file already exists, it is overwritten. /// </summary> /// <param name="pathInfo">The file. </param> /// <param name="bytes">The bytes to write. </param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes(v=vs.110).aspx</remarks> public static void WriteAllBytes( QuickIOPathInfo pathInfo, byte[ ] bytes ) { using ( var fileStream = OpenFileStream( pathInfo, FileAccess.ReadWrite, FileMode.Create, FileShare.None ) ) { fileStream.Seek( 0, SeekOrigin.Begin ); fileStream.Write( bytes, 0, bytes.Length ); } }
/// <summary> /// Initializes a new instance of the QuickIOAbstractBase class, which acts as a wrapper for a file path. /// </summary> /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param> /// <param name="findData"><see cref="Win32FindData"/></param> internal QuickIOFileSystemEntryBase( QuickIOPathInfo pathInfo, Win32FindData findData ) { this.FindData = findData; this.PathInfo = pathInfo; if ( findData != null ) { this.Attributes = findData.dwFileAttributes; } }
/// <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) { FileAttributes updatedAttributes; bool result = QuickIOEngine.TryAddAttribute(info.FullNameUnc, attribute, out updatedAttributes); info.Attributes = updatedAttributes; return(result); }
/// <summary> /// Reads all lines with the specified encoding /// </summary> /// <param name="pathInfo">The file. </param> /// <param name="encoding">The encoding applied to the contents. </param> /// <returns>A string collection containing all lines.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/bsy4fhsa(v=vs.110).aspx</remarks> public static IEnumerable <string> ReadAllLines(QuickIOPathInfo pathInfo, Encoding encoding) { using (var streamReader = new StreamReader(OpenRead(pathInfo.FullNameUnc), encoding)) { while (streamReader.Peek( ) >= 0) { yield return(streamReader.ReadLine( )); } } }
/// <summary> /// File content hash calculation using SHA1 /// </summary> /// <returns><see cref="QuickIOHashResult"/></returns> /// <example> /// <code> /// // Show human readable hash /// QuickIOHashResult hashResult = QuickIOFile.CalculateSha1Hash( "C:\temp\image.bin" ); /// Console.WriteLine("Hash: {0}", hashResult.Format( Encoding.UTF8, "x2" ); /// </code> /// </example> public static QuickIOHashResult CalculateSha1Hash( QuickIOPathInfo pathInfo ) { Contract.Requires( pathInfo != null ); using( var fs = OpenRead( pathInfo ) ) using( var hashAlgorithm = new SHA1Managed() ) { return CalculateHash( hashAlgorithm, fs ); } }
/// <summary> /// Removes the specified attribute from file or directory /// </summary> /// <param name="info">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(QuickIOPathInfo info, FileAttributes attribute) { Contract.Requires(info != null); FileAttributes updatedAttributes; bool result = QuickIOEngine.TryRemoveAttribute(info.FullNameUnc, attribute, out updatedAttributes); info.Attributes = updatedAttributes; return(result); }
/// <summary> /// Appends lines by using the specified encoding. /// If the file does not exist, it creates the file. /// </summary> /// <param name="pathInfo">The file to append the lines to. The file is created if it doesn't exist.</param> /// <param name="contents">The lines to append.</param> /// <param name="encoding">The character encoding.</param> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383356(v=vs.110).aspx</remarks> public static void AppendAllLines( QuickIOPathInfo pathInfo, IEnumerable<string> contents, Encoding encoding ) { var fileStream = OpenAppendFileStream( pathInfo, FileAccess.Write, FileMode.OpenOrCreate, FileShare.Write ); using ( var streamWriter = new StreamWriter( fileStream, encoding ) ) { foreach ( var line in contents ) { streamWriter.WriteLine( line ); } } }
/// <summary> /// Initializes a new instance of the QuickIOAbstractBase class, which acts as a wrapper for a file path. /// </summary> /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param> /// <param name="findData"><see cref="Win32FindData"/></param> internal QuickIOFileSystemEntryBase(QuickIOPathInfo pathInfo, Win32FindData findData) { this.PathInfo = pathInfo; this.FindData = findData; if (findData != null) { this.Attributes = findData.dwFileAttributes; //Changed to allow paths which do not exist: _lastWriteTimeUtc = FindData.GetLastWriteTimeUtc(); _lastAccessTimeUtc = findData.GetLastAccessTimeUtc(); _creationTimeUtc = findData.GetCreationTimeUtc(); } }
/// <summary> /// Initializes a new instance of the QuickIOAbstractBase class, which acts as a wrapper for a file path. /// </summary> /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param> /// <param name="findData"><see cref="Win32FindData"/></param> internal QuickIOFileSystemEntryBase( QuickIOPathInfo pathInfo, Win32FindData findData ) { this.PathInfo = pathInfo; this.FindData = findData; if( findData != null ) { this.Attributes = findData.dwFileAttributes; } _lastWriteTimeUtc = FindData.GetLastWriteTimeUtc(); _lastAccessTimeUtc = findData.GetLastAccessTimeUtc(); _creationTimeUtc = findData.GetCreationTimeUtc(); }
/// <summary> /// Reads the contents of the file into a byte collection. /// </summary> /// <param name="pathInfo">The file. </param> /// <param name="readBuffer">Read buffer byte size</param> /// <returns>A byte collection containing the contents.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.readallbytes(v=vs.110).aspx</remarks> public static byte[] ReadAllBytes(QuickIOPathInfo pathInfo, Int32 readBuffer = 1024) { using (var readStream = OpenRead(pathInfo)) { var buffer = new byte[readBuffer]; using (var ms = new MemoryStream( )) { int read; while ((read = readStream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } return(ms.ToArray( )); } } }
/// <summary> /// Supply the path to the file or directory and a user or group. /// Access checks are done /// during instantiation to ensure we always have a valid object /// </summary> /// <param name="pathInfo"></param> /// <param name="principal"></param> public QuickIOFileSystemSecurity( QuickIOPathInfo pathInfo, WindowsIdentity principal ) { if ( pathInfo == null ) { throw new ArgumentNullException( "pathInfo" ); } if ( principal == null ) { throw new ArgumentNullException( "principal" ); } this.PathInfo = pathInfo; this.WindowsIdentity = principal; Refresh( ); }
/// <summary> /// Reads the contents of the file into a byte collection. /// </summary> /// <param name="pathInfo">The file. </param> /// <returns>A byte collection containing the contents.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.readallbytes(v=vs.110).aspx</remarks> public static byte[] ReadAllBytes( QuickIOPathInfo pathInfo ) { using ( var readStream = OpenRead( pathInfo ) ) { var buffer = new byte[ 16 * 1024 ]; using ( var ms = new MemoryStream( ) ) { int read; while ( ( read = readStream.Read( buffer, 0, buffer.Length ) ) > 0 ) { ms.Write( buffer, 0, read ); } return ms.ToArray( ); } } }
/// <summary> /// Supply the path to the file or directory and a user or group. /// Access checks are done /// during instantiation to ensure we always have a valid object /// </summary> /// <param name="pathInfo"></param> /// <param name="principal"></param> public QuickIOFileSystemSecurity( QuickIOPathInfo pathInfo, WindowsIdentity principal ) { #region Input Validation Contract.Requires( pathInfo != null ); Contract.Requires( principal != null ); if( pathInfo == null ) { throw new ArgumentNullException( nameof( pathInfo ) ); } if( principal == null ) { throw new ArgumentNullException( nameof( principal ) ); } #endregion Input Validation this._pathInfo = pathInfo; this._windowsIdentity = principal; Refresh(); }
/// <summary> /// Supply the path to the file or directory and a user or group. /// Access checks are done /// during instantiation to ensure we always have a valid object /// </summary> /// <param name="pathInfo"></param> /// <param name="principal"></param> public QuickIOFileSystemSecurity(QuickIOPathInfo pathInfo, WindowsIdentity principal) { #region Input Validation Contract.Requires(pathInfo != null); Contract.Requires(principal != null); if (pathInfo == null) { throw new ArgumentNullException(nameof(pathInfo)); } if (principal == null) { throw new ArgumentNullException(nameof(principal)); } #endregion Input Validation this._pathInfo = pathInfo; this._windowsIdentity = principal; Refresh(); }
/// <summary> /// Defines the time at which the file or directory was last written /// </summary> /// <param name="info">Affected file or directory</param> /// <param name="lastWriteTime">The time that is to be used</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setlastwritetime(v=vs.110).aspx</remarks> public static void SetLastWriteTime( QuickIOPathInfo info, DateTime lastWriteTime ) { SetLastWriteTimeUtc( info, lastWriteTime.ToUniversalTime( ) ); }
/// <summary> /// Returns the creation time of the file or directory /// </summary> /// <param name="info">Affected file or directory</param> /// <returns>A <see cref="DateTime"/> structure.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.getcreationtime(v=vs.110).aspx</remarks> /// <exception cref="PathNotFoundException">No entry found for passed path</exception> public static DateTime GetCreationTime( QuickIOPathInfo info ) { return GetCreationTimeUtc( info ).ToLocalTime( ); }
/// <summary> /// Defines the time at which the file or directory was created /// </summary> /// <param name="info">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(QuickIOPathInfo info, DateTime creationTime) { QuickIOEngine.SetCreationTimeUtc(info.FullNameUnc, creationTime.ToUniversalTime( )); }
/// <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 ); }
/// <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 ) { InternalQuickIO.SetAttributes( info, attributes); }
/// <summary> /// Checks whether the given directory exists. /// </summary> /// <param name="pathInfo">The path to test. </param> /// <returns>true if exists; otherwise, false.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.directory.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(QuickIOPathInfo pathInfo) { return(Exists(pathInfo.FullNameUnc)); }
/// <summary> /// Returns the creation time of the file or directory (UTC) /// </summary> /// <param name="info">Affected file or directory</param> /// <returns>A <see cref="DateTime"/> structure. (UTC)</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.getcreationtimeutc(v=vs.110).aspx</remarks> /// <exception cref="PathNotFoundException">No entry found for passed path</exception> public static DateTime GetCreationTimeUtc(QuickIOPathInfo info) { return(info.FindData.GetCreationTimeUtc( )); }
/// <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(QuickIOPathInfo info, DateTime lastWriteTimeUtc) { QuickIOEngine.SetLastWriteTimeUtc(info.FullNameUnc, lastWriteTimeUtc); }
/// <summary> /// Defines the time at which the file or directory was last written /// </summary> /// <param name="info">Affected file or directory</param> /// <param name="lastWriteTime">The time that is to be used</param> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.setlastwritetime(v=vs.110).aspx</remarks> public static void SetLastWriteTime(QuickIOPathInfo info, DateTime lastWriteTime) { SetLastWriteTimeUtc(info, lastWriteTime.ToUniversalTime( )); }
/// <summary> /// Defines the time at which the file or directory was last accessed /// </summary> /// <param name="info">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.setlastaccesstime(v=vs.110).aspx</remarks> public static void SetLastAccessTime(QuickIOPathInfo info, DateTime lastAccessTime) { QuickIOEngine.SetLastAccessTimeUtc(info.FullNameUnc, lastAccessTime.ToUniversalTime( )); }
/// <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(QuickIOPathInfo info, DateTime creationTimeUtc) { QuickIOEngine.SetCreationTimeUtc(info.FullNameUnc, creationTimeUtc); }
/// <summary> /// Returns the creation time of the file or directory /// </summary> /// <param name="info">Affected file or directory</param> /// <returns>A <see cref="DateTime"/> structure.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.getcreationtime(v=vs.110).aspx</remarks> /// <exception cref="PathNotFoundException">No entry found for passed path</exception> public static DateTime GetCreationTime(QuickIOPathInfo info) { return(GetCreationTimeUtc(info).ToLocalTime( )); }
/// <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( QuickIOPathInfo info, DateTime lastWriteTimeUtc ) { InternalQuickIO.SetLastWriteTimeUtc( info, lastWriteTimeUtc ); }
/// <summary> /// Returns the creation time of the file or directory (UTC) /// </summary> /// <param name="info">Affected file or directory</param> /// <returns>A <see cref="DateTime"/> structure. (UTC)</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.getcreationtimeutc(v=vs.110).aspx</remarks> /// <exception cref="PathNotFoundException">No entry found for passed path</exception> public static DateTime GetCreationTimeUtc( QuickIOPathInfo info ) { return info.FindData.GetCreationTimeUtc( ); }
/// <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) { Contract.Requires(info != null); return(AddAttribute(info.FullNameUnc, attribute)); }
/// <summary> /// Gets the directory statistics: total files, folders and bytes /// </summary> /// <param name="pathInfo"></param> /// <returns>A <see cref="QuickIOFolderStatisticResult"/> object that holds the folder statistics such as number of folders, files and total bytes</returns> /// <example> /// This example shows how to call <see> /// <cref>GetStatistics</cref> /// </see> /// with <see cref="QuickIOPathInfo"/> and write the result to the console. /// <code> ///public static void GetStatistics_With_PathInfo_Example() ///{ /// QuickIOPathInfo targetDirectoryPathInfo = new QuickIOPathInfo( @"C:\temp\QuickIOTest" ); /// /// // Get statistics /// QuickIOFolderStatisticResult stats = QuickIODirectory.GetStatistics( targetDirectoryPathInfo ); /// /// // Output /// Console.WriteLine( "[Stats] Folders: '{0}' Files: '{1}' Total TotalBytes '{2}'", stats.FolderCount, stats.FileCount, stats.TotalBytes ); ///} /// </code> /// </example> public static QuickIOFolderStatisticResult GetStatistics(QuickIOPathInfo pathInfo) { return(QuickIOEngine.GetDirectoryStatistics(pathInfo)); }
/// <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); SetAttributes(info.FullNameUnc, attributes); }
/// <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, attribute ); }
/// <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) { Contract.Requires(info != null); return(GetAttributes(info.FullNameUnc)); }
/// <summary> /// Sets the time the file was created. /// </summary> /// <param name="info">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(QuickIOPathInfo info, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime) { QuickIOEngine.SetAllFileTimes(info.FullNameUnc, creationTime.ToUniversalTime( ), lastAccessTime.ToUniversalTime( ), lastWriteTime.ToUniversalTime( )); }
/// <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 Task<bool> AddAttributeAsync( QuickIOPathInfo info, FileAttributes attribute ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( ( ) => QuickIOFile.AddAttribute( info, 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 Task SetAttributesAsync( QuickIOPathInfo info, FileAttributes attributes ) { return NETCompatibility.AsyncExtensions.ExecuteAsync( ( ) => QuickIOFile.SetAttributes( info, attributes) ); }
/// <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(QuickIOPathInfo info, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc) { QuickIOEngine.SetAllFileTimes(info.FullNameUnc, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc); }
/// <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 Task<FileAttributes> GetAttributesAsync( QuickIOPathInfo info ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( ( ) => QuickIOFile.GetAttributes( info ) ); }
/// <summary> /// Returns the time of the file or directory was last written (UTC) /// </summary> /// <param name="info">Affected file or directory</param> /// <returns>A <see cref="DateTime"/> structure. (UTC)</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.file.getlastwritetimeutc(v=vs.110).aspx</remarks> /// <exception cref="PathNotFoundException">No entry found for passed path</exception> public static DateTime GetLastWriteTimeUtc(QuickIOPathInfo info) { return(info.FindData.GetLastWriteTimeUtc( )); }