/// <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> /// Creates a new directory. If <paramref name="recursive"/> is false, the parent directory must exists. /// </summary> /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param> /// <param name="recursive">If <paramref name="recursive"/> is false, the parent directory must exist.</param> /// <exception cref="PathAlreadyExistsException">The specified path already exists.</exception> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static void CreateDirectory( QuickIOPathInfo pathInfo, bool recursive = false ) { if ( recursive ) { var parent = pathInfo.Parent; if ( parent.IsRoot ) { // Root if ( !parent.Exists ) { throw new PathNotFoundException( "Root path does not exists. You cannot create a root this way.", parent.FullName ); } } else if ( !parent.Exists ) { CreateDirectory( parent, recursive ); } } if ( pathInfo.CheckExistance( QuickIOFileSystemEntryType.Directory ) ) { return; } var created = Win32SafeNativeMethods.CreateDirectory( pathInfo.FullNameUnc, IntPtr.Zero ); var win32Error = Marshal.GetLastWin32Error( ); if ( !created ) { InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } }
/// <summary> /// Returns the <see cref="SafeFileHandle"/> and fills <see cref="Win32FindData"/> from the passes path. /// </summary> /// <param name="pathInfo">Path to the file system entry</param> /// <returns><see cref="SafeFileHandle"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static SafeFileHandle CreateSafeFileHandle( QuickIOPathInfo pathInfo ) { Contract.Requires( pathInfo != null ); Contract.Ensures( Contract.Result<SafeFileHandle>() != null ); return CreateSafeFileHandle( pathInfo.FullNameUnc ); }
/// <summary> /// Returns the <see cref="SafeFileHandle"/> and fills <see cref="Win32FindData"/> from the passes path. /// </summary> /// <param name="pathInfo">Path to the file system entry</param> /// <returns><see cref="SafeFileHandle"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static SafeFileHandle CreateSafeFileHandle(QuickIOPathInfo pathInfo) { Contract.Requires(pathInfo != null); Contract.Ensures(Contract.Result <SafeFileHandle>() != null); return(CreateSafeFileHandle(pathInfo.FullNameUnc)); }
/// <summary> /// Adds a file attribute /// </summary> /// <param name="pathInfo">Affected target</param> /// <param name="attribute">Attribute to add</param> /// <returns>true if added. false if already exists in attributes</returns> public static Boolean AddAttribute( QuickIOPathInfo pathInfo, FileAttributes attribute ) { if ( ( pathInfo.Attributes & attribute ) != attribute ) { var attributes = pathInfo.Attributes; attributes |= attribute; SetAttributes( pathInfo, attributes ); return true; } return false; }
/// <summary> /// Sets the time at which the file or directory was last accessed to (UTC) /// </summary> /// <param name="pathInfo">Affected file or directory</param> /// <param name="utcTime">The time that is to be used (UTC)</param> public static void SetLastAccessTimeUtc(QuickIOPathInfo pathInfo, DateTime utcTime) { Contract.Requires(pathInfo != null); long longTime = utcTime.ToFileTime(); using (SafeFileHandle fileHandle = OpenReadWriteFileSystemEntryHandle(pathInfo.FullNameUnc)) { if (!Win32SafeNativeMethods.SetLastAccessFileTime(fileHandle, IntPtr.Zero, ref longTime, IntPtr.Zero)) { int win32Error = Marshal.GetLastWin32Error(); Win32ErrorCodes.NativeExceptionMapping(pathInfo.FullName, win32Error); } } }
/// <summary> /// Sets the dates and times of given directory or file. /// </summary> /// <param name="pathInfo">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 SetAllFileTimes(QuickIOPathInfo pathInfo, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc) { Contract.Requires(pathInfo != null); long longCreateTime = creationTimeUtc.ToFileTime(); long longAccessTime = lastAccessTimeUtc.ToFileTime(); long longWriteTime = lastWriteTimeUtc.ToFileTime(); using (SafeFileHandle fileHandle = OpenReadWriteFileSystemEntryHandle(pathInfo.FullNameUnc)) { if (Win32SafeNativeMethods.SetAllFileTimes(fileHandle, ref longCreateTime, ref longAccessTime, ref longWriteTime) == 0) { int win32Error = Marshal.GetLastWin32Error(); Win32ErrorCodes.NativeExceptionMapping(pathInfo.FullName, win32Error); } } }
/// <summary> /// Checks whether the path with the expected system entry type exists /// </summary> /// <param name="path">Path to 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( String path, QuickIOFileSystemEntryType systemEntryType ) { var info = new QuickIOPathInfo( path ); if ( !info.Exists ) { return false; } if ( info.IsRoot && systemEntryType == QuickIOFileSystemEntryType.Directory ) // root is always directory { return true; } if ( info.SystemEntryType == systemEntryType ) { return true; } throw new UnmatchedFileSystemEntryTypeException( systemEntryType, info.SystemEntryType, info.FullName ); }
public void QuickIOPathInfoFile() { string parent = QuickIOPath.Combine(CurrentPath(), "_TestFiles"); string fullpath = QuickIOPath.Combine(CurrentPath(), "_TestFiles", "ExistingTestFile.txt"); string fullPathUnc = QuickIOPath.ToPathUnc(fullpath); string root = QuickIOPath.GetPathRoot(fullpath); QuickIOPathInfo pi = new QuickIOPathInfo(fullpath); pi.Should().NotBe(null); pi.Name.Should().Be("ExistingTestFile.txt"); pi.FullName.Should().Be(fullpath); pi.FullNameUnc.Should().Be(fullPathUnc); pi.Parent.Should().Be(parent); pi.Root.Should().Be(root); pi.IsRoot.Should().Be(false); pi.FindData.Should().NotBe(null); InternalHelpers.ContainsFileAttribute(pi.Attributes, FileAttributes.Directory).Should().Be(false); pi.Exists.Should().Be(true); pi.SystemEntryType.Should().Be(QuickIOFileSystemEntryType.File); }
public void QuickIOPathInfoFile() { string parent = QuickIOPath.Combine( CurrentPath(), "_TestFiles" ); string fullpath = QuickIOPath.Combine( CurrentPath(), "_TestFiles", "ExistingTestFile.txt" ); string fullPathUnc = QuickIOPath.ToPathUnc( fullpath ); string root = QuickIOPath.GetPathRoot( fullpath ); QuickIOPathInfo pi = new QuickIOPathInfo( fullpath ); pi.Should().NotBe( null ); pi.Name.Should().Be( "ExistingTestFile.txt" ); pi.FullName.Should().Be( fullpath ); pi.FullNameUnc.Should().Be( fullPathUnc ); pi.Parent.Should().Be( parent ); pi.Root.Should().Be( root ); pi.IsRoot.Should().Be( false ); pi.FindData.Should().NotBe( null ); InternalHelpers.ContainsFileAttribute( pi.Attributes, FileAttributes.Directory ).Should().Be( false ); pi.Exists.Should().Be( true ); pi.SystemEntryType.Should().Be( QuickIOFileSystemEntryType.File ); }
///// <summary> ///// Returns the <see cref="Win32FindData"/> from specified <paramref name="fullUncPath"/> ///// </summary> ///// <param name="fullUncPath">Path to the file system entry</param> ///// <returns><see cref="Win32FindData"/></returns> ///// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> /// /// <summary> /// Returns the <see cref="Win32FindData"/> from specified <paramref name="pathInfo"/> /// </summary> /// <param name="pathInfo">Path to the file system entry</param> /// <returns><see cref="Win32FindData"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static Win32FindData GetFindDataFromPath( QuickIOPathInfo pathInfo ) { var win32FindData = new Win32FindData( ); int win32Error; using ( var fileHandle = FindFirstSafeFileHandle( pathInfo.FullNameUnc, win32FindData, out win32Error ) ) { // Take care of invalid handles if ( fileHandle.IsInvalid ) { InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } // Treffer auswerten // Ignore . and .. directories if ( !InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) ) { return win32FindData; } } throw new PathNotFoundException( pathInfo.FullName ); }
/// <summary> /// Gets the <see cref="Win32FindData"/> from the passed <see cref="QuickIOPathInfo"/> /// </summary> /// <param name="pathInfo">Path to the file system entry</param> /// <param name="estimatedFileSystemEntryType">Estimated Type (File or Directory)</param> /// <returns><seealso cref="Win32FindData"/></returns> /// <exception cref="UnmatchedFileSystemEntryTypeException">Searched for file but found folder or vise versa.</exception> ///<exception cref="PathNotFoundException">No entry found for passed path</exception> public static Win32FindData GetFindDataFromPath( QuickIOPathInfo pathInfo, QuickIOFileSystemEntryType? estimatedFileSystemEntryType ) { return GetFindDataFromPath( pathInfo.FullNameUnc, estimatedFileSystemEntryType ); }
/// <summary> /// Reurns true if passed path exists /// </summary> /// <param name="pathInfo">Path to check</param> public static Boolean Exists( QuickIOPathInfo pathInfo ) { return Exists( pathInfo.FullNameUnc ); }
/// <summary> /// Determines the statistics of the given directory. This includes the number of files, folders and the total size in bytes. /// </summary> /// <param name="pathInfo">PathInfo of the directory to generate the statistics.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>Provides the statistics of the directory</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static QuickIOFolderStatisticResult GetDirectoryStatistics( QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return GetDirectoryStatistics( pathInfo.FullNameUnc, enumerateOptions ); }
/// <summary> /// Deletes all files in the given directory. On request all contents, too. /// </summary> /// <param name="pathInfo">PathInfo of directory to clear</param> /// <param name="recursive">If <paramref name="recursive"/> is true then all subfolders are also deleted.</param> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> /// <exception cref="DirectoryNotEmptyException">The directory is not empty.</exception> /// <remarks>Function loads every file and attribute. Alls read-only flags will be removed before removing.</remarks> public static void DeleteDirectory( QuickIOPathInfo pathInfo, bool recursive = false ) { DeleteDirectory( new QuickIODirectoryInfo( pathInfo ), recursive ); }
/// <summary> /// Removes a file. /// </summary> /// <param name="pathInfo">PathInfo of the file to remove</param> /// <exception cref="FileNotFoundException">This error is fired if the specified file to remove does not exist.</exception> public static void DeleteFile( QuickIOPathInfo pathInfo ) { RemoveAttribute( pathInfo, FileAttributes.ReadOnly ); DeleteFile( pathInfo.FullNameUnc ); }
/// <summary> /// Determined all sub file system entries of a directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<KeyValuePair<String, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( QuickIOPathInfo pathInfo, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return EnumerateFileSystemEntryPaths( pathInfo.FullNameUnc, pattern, searchOption, enumerateOptions, pathFormatReturn ); }
/// <summary> /// Determines the statistics of the given directory. This includes the number of files, folders and the total size in bytes. /// </summary> /// <param name="pathInfo">PathInfo of the directory to generate the statistics.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>Provides the statistics of the directory</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static QuickIOFolderStatisticResult GetDirectoryStatistics(QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None) { throw new NotImplementedException(); }
/// <summary> /// Returns the <see cref="SafeFileHandle"/> and fills <see cref="Win32FindData"/> from the passes path. /// </summary> /// <param name="info">Path to the file system entry</param> /// <returns><see cref="SafeFileHandle"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static SafeFileHandle CreateSafeFileHandle( QuickIOPathInfo info ) { return CreateSafeFileHandle( info.FullNameUnc ); }
/// <summary> /// Determined metadata of directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <returns><see cref="QuickIODirectoryMetadata"/> started with the given directory</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static QuickIODirectoryMetadata EnumerateDirectoryMetadata( QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return EnumerateDirectoryMetadata( pathInfo.FullNameUnc, pathInfo.FindData, enumerateOptions ); }
/// <summary> /// Sets the time at which the file or directory was last written to (UTC) /// </summary> /// <param name="pathInfo">Affected file or directory</param> /// <param name="utcTime">The time that is to be used (UTC)</param> public static void SetLastWriteTimeUtc( QuickIOPathInfo pathInfo, DateTime utcTime ) { var longTime = utcTime.ToFileTime( ); using ( var fileHandle = OpenReadWriteFileSystemEntryHandle( pathInfo.FullNameUnc ) ) { if ( !Win32SafeNativeMethods.SetLastWriteFileTime( fileHandle, IntPtr.Zero, IntPtr.Zero, ref longTime ) ) { var win32Error = Marshal.GetLastWin32Error( ); InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } } }
/// <summary> /// Sets the dates and times of given directory or file. /// </summary> /// <param name="pathInfo">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 SetAllFileTimes( QuickIOPathInfo pathInfo, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc ) { var longCreateTime = creationTimeUtc.ToFileTime( ); var longAccessTime = lastAccessTimeUtc.ToFileTime( ); var longWriteTime = lastWriteTimeUtc.ToFileTime( ); using ( var fileHandle = OpenReadWriteFileSystemEntryHandle( pathInfo.FullNameUnc ) ) { if ( Win32SafeNativeMethods.SetAllFileTimes( fileHandle, ref longCreateTime, ref longAccessTime, ref longWriteTime ) == 0 ) { var win32Error = Marshal.GetLastWin32Error( ); InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } } }
/// <summary> /// Returns the root information /// </summary> /// <param name="info">A file or directory. </param> /// <returns>A QuickIOPathInfo that represents the root or null if <paramref name="info"/> is root.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.directory.getdirectoryroot(v=vs.110).aspx</remarks> public static QuickIOPathInfo GetDirectoryRoot(QuickIOPathInfo info) { return(new QuickIOPathInfo(info.Root)); }
/// <summary> /// Reurns true if passed path exists /// </summary> /// <param name="pathInfo">Path to check</param> public static Boolean Exists( QuickIOPathInfo pathInfo ) { var win32FindData = new Win32FindData( ); int win32Error; var path = pathInfo.FullNameUnc; if ( pathInfo.IsRoot ) { path = QuickIOPath.Combine( path, "*" ); } using ( var fileHandle = FindFirstSafeFileHandle( path, win32FindData, out win32Error ) ) { // Take care of invalid handles return !fileHandle.IsInvalid; } }
/// <summary> /// Returns the root information /// </summary> /// <param name="info">A file or directory. </param> /// <returns>A QuickIOPathInfo that represents the root or null if <paramref name="info"/> is root.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.directory.getdirectoryroot(v=vs.110).aspx</remarks> public static QuickIOPathInfo GetDirectoryRoot( QuickIOPathInfo info ) { return info.IsRoot ? null : GetDirectoryRoot( info.Root ); }
/// <summary> /// Loads a file from specified path /// </summary> /// <param name="pathInfo">Full path</param> /// <returns><see cref="QuickIOFileInfo"/></returns> /// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not a file; it's a directory.</exception> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static QuickIOFileInfo LoadFileFromPathInfo( QuickIOPathInfo pathInfo ) { // Find First file Win32FindData findData; if ( TryGetFindDataFromPath( pathInfo, out findData ) ) { // Entry found, check for file if ( InternalQuickIOCommon.DetermineFileSystemEntry( findData ) == QuickIOFileSystemEntryType.File ) { return new QuickIOFileInfo( pathInfo, findData ); } throw new UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType.File, QuickIOFileSystemEntryType.Directory, pathInfo.FullName ); } // Nothing found throw new PathNotFoundException( pathInfo.FullName ); }
/// <summary> /// Determined all files of a directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <returns>Collection of files</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<QuickIOFileInfo> EnumerateFiles( QuickIOPathInfo pathInfo, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions ) { return EnumerateFiles( pathInfo.FullNameUnc, searchOption, enumerateOptions ); }
/// <summary> /// Sets the specified <see cref="FileAttributes"/> of the entry on the specified path. /// </summary> /// <param name="pathInfo">The path to the entry.</param> /// <param name="attributes">A bitwise combination of the enumeration values.</param> /// <exception cref="Win32Exception">Unmatched Exception</exception> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static void SetAttributes( QuickIOPathInfo pathInfo, FileAttributes attributes ) { if ( !Win32SafeNativeMethods.SetFileAttributes( pathInfo.FullNameUnc, ( uint ) attributes ) ) { var win32Error = Marshal.GetLastWin32Error( ); InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } }
/// <summary> /// Determined all sub system entries of a directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<KeyValuePair<QuickIOPathInfo, QuickIOFileSystemEntryType>> EnumerateFileSystemEntries( QuickIOPathInfo pathInfo, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions ) { return EnumerateFileSystemEntries( pathInfo.FullNameUnc, searchOption, enumerateOptions ); }
/// <summary> /// Gets the <see cref="Win32FindData"/> from the passed path. /// </summary> /// <param name="pathInfo">Path</param> /// <param name="pathFindData"><seealso cref="Win32FindData"/>. Will be null if path does not exist.</param> /// <returns>true if path is valid and <see cref="Win32FindData"/> is set</returns> /// <remarks> /// <see> /// <cref>QuickIOCommon.NativeExceptionMapping</cref> /// </see> if invalid handle found. /// </remarks> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static bool TryGetFindDataFromPath( QuickIOPathInfo pathInfo, out Win32FindData pathFindData ) { var win32FindData = new Win32FindData( ); int win32Error; //var path = pathInfo.FullNameUnc; //if ( pathInfo.IsRoot ) //{ // path = QuickIOPath.Combine( path, QuickIOPatternConstants.All ); //} using ( var fileHandle = FindFirstSafeFileHandle( pathInfo.FullNameUnc, win32FindData, out win32Error ) ) { // Take care of invalid handles if ( fileHandle.IsInvalid ) { InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } // Treffer auswerten // Ignore . and .. directories if ( !InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) ) { pathFindData = win32FindData; return true; } } pathFindData = null; return false; }
/// <summary> /// Determined all sub file system entries of a directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<KeyValuePair<String, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( QuickIOPathInfo pathInfo, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return EnumerateFileSystemEntryPaths( pathInfo.FullNameUnc, searchOption, enumerateOptions, pathFormatReturn ); }
/// <summary> /// Determined all subfolders of a directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <returns><see cref="QuickIODirectoryInfo"/> collection of subfolders</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<QuickIODirectoryInfo> EnumerateDirectories( QuickIOPathInfo pathInfo, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { // Match for start of search var currentPath = QuickIOPath.Combine( pathInfo.FullNameUnc, pattern ); // Find First file var win32FindData = new Win32FindData( ); int win32Error; using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) ) { // Take care of invalid handles if ( fileHandle.IsInvalid ) { if ( win32Error != Win32ErrorCodes.ERROR_NO_MORE_FILES ) { InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } if ( EnumerationHandleInvalidFileHandle( pathInfo.FullName, enumerateOptions, win32Error ) ) { yield return null; } } // Treffer auswerten do { // Ignore . and .. directories if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) ) { continue; } // Create hit for current search result var resultPath = QuickIOPath.Combine( pathInfo.FullName, win32FindData.cFileName ); // Check for Directory if ( InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) ) { yield return new QuickIODirectoryInfo( resultPath, win32FindData ); // SubFolders?! if ( searchOption == SearchOption.AllDirectories ) { foreach ( var match in EnumerateDirectories( new QuickIOPathInfo( resultPath, win32FindData.cFileName ), pattern, searchOption, enumerateOptions ) ) { yield return match; } } } // Create new FindData object for next result win32FindData = new Win32FindData( ); } // Search for next entry while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) ); } }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the file on the entry. /// </summary> /// <param name="pathInfo">The path to the entry. </param> /// <returns>The <see cref="FileAttributes"/> of the file on the entry.</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static FileAttributes GetAttributes( QuickIOPathInfo pathInfo ) { return pathInfo.Attributes; }
/// <summary> /// Determined all files of a directory /// </summary> /// <param name="pathInfo">Path of the directory</param> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>Collection of files</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<QuickIOFileInfo> EnumerateFiles( QuickIOPathInfo pathInfo, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return EnumerateFiles( pathInfo.FullNameUnc, pattern, searchOption, enumerateOptions ); }
/// <summary> /// Creates a new file. /// </summary> /// <exception cref="PathAlreadyExistsException">The specified path already exists.</exception> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static void CreateFile( QuickIOPathInfo pathInfo, FileAccess fileAccess = FileAccess.Write, FileShare fileShare = FileShare.None, FileMode fileMode = FileMode.Create, FileAttributes fileAttributes = 0 ) { using ( var fileHandle = Win32SafeNativeMethods.CreateFile( pathInfo.FullNameUnc, fileAccess, fileShare, IntPtr.Zero, fileMode, fileAttributes, IntPtr.Zero ) ) { var win32Error = Marshal.GetLastWin32Error( ); if ( fileHandle.IsInvalid ) { InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error ); } } }
/// <summary> /// Determines the statistics of the given directory. This includes the number of files, folders and the total size in bytes. /// </summary> /// <param name="pathInfo">PathInfo of the directory to generate the statistics.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>Provides the statistics of the directory</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static QuickIOFolderStatisticResult GetDirectoryStatistics( QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { throw new NotImplementedException(); }
/// <summary> /// Sets the specified <see cref="FileAttributes"/> of the entry on the specified path. /// </summary> /// <param name="pathInfo">The path to the entry.</param> /// <param name="attributes">A bitwise combination of the enumeration values.</param> /// <exception cref="Win32Exception">Unmatched Exception</exception> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static Task SetAttributesAsync( QuickIOPathInfo pathInfo, FileAttributes attributes ) { return NETCompatibility.AsyncExtensions.ExecuteAsync( () => SetAttributes( pathInfo, attributes ) ); }