/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption">Specifiy depth with <see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options</param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> public IEnumerable<string> EnumerateFilePaths( String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { Contract.Requires( !String.IsNullOrWhiteSpace( pattern ) ); Contract.Ensures( Contract.Result<IEnumerable<string>>() != null ); return QuickIODirectory.EnumerateFilePaths( FullNameUnc, pattern, searchOption, pathFormatReturn, enumerateOptions ); }
/// <summary> /// Returns an enumerable collection of directory names in a specified path. /// </summary> /// <param name="info">The directory to search.</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">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383304(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateDirectoryPaths( QuickIODirectoryInfo info, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { Contract.Requires( info != null ); Contract.Requires( !String.IsNullOrWhiteSpace( pattern ) ); return EnumerateDirectoryPaths( info.FullNameUnc, pattern, searchOption, pathFormatReturn, enumerateOptions ); }
/// <summary> /// Returns an enumerable collection of directory names in a specified path. /// </summary> /// <param name="path">The directory to search.</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">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383304(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateDirectoryPaths( string path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { Contract.Requires( !String.IsNullOrWhiteSpace( path ) ); Contract.Requires( !String.IsNullOrWhiteSpace( pattern ) ); return InternalEnumerateFileSystem.EnumerateSystemPaths( path, pattern, searchOption, enumerateOptions, pathFormatReturn, QuickIOFileSystemEntryType.Directory ); }
internal static Boolean TryParseShare(string path, QuickIOPathType shouldBe, out string serverName, out string shareName, out string[] pathElements) { serverName = null; shareName = null; pathElements = null; // Validate input if (String.IsNullOrWhiteSpace(path)) { return(false); } if (shouldBe == QuickIOPathType.UNC) { path = path.Substring(QuickIOPath.UncSharePathPrefix.Length); } // try to found server and name string[] names = path.Trim('\\' /*trim start and end */).Split('\\'); if (names.Length < 2) { // if less than two it is invalid return(false); } serverName = names[0]; shareName = names[1]; pathElements = names.Skip(2).ToArray(); return(true); }
/// <summary> /// Search Exection /// </summary> /// <param name="uncDirectoryPath">Start directory path</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> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="filterType"><see cref="QuickIOFileSystemEntryType"/></param> /// <returns>Collection of path</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static IEnumerable<String> EnumerateSystemPaths( String uncDirectoryPath, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOFileSystemEntryType? filterType = null ) { Contract.Requires( !String.IsNullOrWhiteSpace( uncDirectoryPath ) ); Contract.Ensures( Contract.Result<IEnumerable<String>>() != null ); IEnumerable<QuickIOFileSystemEntry> entries = EnumerateFileSystemEntries( uncDirectoryPath, pattern, searchOption, enumerateOptions ); // filter? if( filterType != null ) { entries = entries.Where( entry => entry.Type == filterType ); } // TODO: path format return entries.Select( entry => entry.Path ); }
/// <summary> /// Determined all files paths of a directory /// </summary> /// <param name="path">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 file paths</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<String> EnumerateFilePaths( String path, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return FindPaths( path, pattern, searchOption, QuickIOFileSystemEntryType.File, enumerateOptions, pathFormatReturn ); }
/// <summary> /// Search Exection /// </summary> /// <param name="uncDirectoryPath">Start directory path</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> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="filterType"><see cref="QuickIOFileSystemEntryType"/></param> /// <returns>Collection of path</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> private static IEnumerable<String> FindPaths( String uncDirectoryPath, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOFileSystemEntryType? filterType = null, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { // Result Container var results = new List<String>( ); // Match for start of search var currentPath = QuickIOPath.Combine( uncDirectoryPath, 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 && EnumerationHandleInvalidFileHandle( uncDirectoryPath, enumerateOptions, win32Error ) ) { return new List<String>( ); } // Treffer auswerten do { // Ignore . and .. directories if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) ) { continue; } // Create hit for current search result var resultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName ); // if it's a file, add to the collection if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) ) { if ( filterType != null && ( ( QuickIOFileSystemEntryType ) filterType == QuickIOFileSystemEntryType.File ) ) { // It's a file results.Add( FormatPathByType( pathFormatReturn, resultPath ) ); } } else { // It's a directory // Check for search searchFocus directories if ( filterType != null && ( ( QuickIOFileSystemEntryType ) filterType == QuickIOFileSystemEntryType.Directory ) ) { results.Add( FormatPathByType( pathFormatReturn, resultPath ) ); } // SubFolders?! if ( searchOption == SearchOption.AllDirectories ) { var r = new List<String>( FindPaths( resultPath, pattern, searchOption, filterType, enumerateOptions ) ); if ( r.Count > 0 ) { results.AddRange( r ); } } } // Create new FindData object for next result win32FindData = new Win32FindData( ); } // Search for next entry while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) ); } // Return result; return results; }
/// <summary> /// Returns an enumerable collection of directory names in a specified path. /// </summary> /// <param name="info">The directory to search.</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">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383304(v=vs.110).aspx</remarks> public static IEnumerable <string> EnumerateDirectoryPaths(QuickIODirectoryInfo info, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None) { Contract.Requires(info != null); Contract.Requires(!String.IsNullOrWhiteSpace(pattern)); return(EnumerateDirectoryPaths(info.FullNameUnc, pattern, searchOption, pathFormatReturn, enumerateOptions)); }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="path">The directory to search. </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">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383458(v=vs.110).aspx</remarks> public static IEnumerable <string> EnumerateFilePaths(string path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None) { return(InternalEnumerateFileSystem.EnumerateSystemPaths(path, pattern, searchOption, enumerateOptions, pathFormatReturn, QuickIOFileSystemEntryType.File)); }
/// <summary> /// Determined all files paths of a directory /// </summary> /// <param name="path">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 file paths</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> internal static IEnumerable<String> EnumerateFilePaths( String path, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return FindPaths( path, searchOption, QuickIOFileSystemEntryType.File, enumerateOptions, pathFormatReturn ); }
/// <summary> /// Returns an enumerable collection of directory names in a specified path. /// </summary> /// <param name="path">The directory to search.</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383304(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateDirectoryPaths( string path, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return EnumerateDirectoryPaths( new QuickIOPathInfo( path ), searchOption, pathFormatReturn, enumerateOptions ); }
/// <summary> /// Returns an enumerable collection of file names in a specified path in a seperate task created by the default <see cref="TaskScheduler"/>. /// </summary> /// <param name="info">The directory to search. </param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks><b>Requires .NET 4.0 or higher</b><br /><u>Warning:</u> parallel file system browsing on the same hard disk (HDD/SSD) will decrease performance. Use this only on stripped RAIDs or with network shares.</remarks> public static Task<IEnumerable<string>> EnumerateFilePathsAsync( QuickIOPathInfo info, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( () => InternalQuickIO.EnumerateFilePaths( info.FullNameUnc, searchOption, enumerateOptions, pathFormatReturn ) ); }
/// <summary> /// Returns an enumerable collection of file names and directory names that match a search pattern in a specified path, and optionally searches subdirectories. /// </summary> /// <param name="searchOption">Specifiy depth with <see cref="SearchOption"/></param> /// <returns>An enumerable collection of file-system entries in the directory specified by path and that match the specified search pattern and option.</returns> /// <remarks><b>Requires .NET 4.0 or higher</b><br /><u>Warning:</u> parallel file system browsing on the same hard disk (HDD/SSD) will decrease performance. Use this only on stripped RAIDs or with network shares.</remarks> public IEnumerable<KeyValuePair<string, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return QuickIODirectory.EnumerateFileSystemEntryPaths( PathInfo, searchOption, pathFormatReturn, enumerateOptions ); }
/// <summary> /// Returns an enumerable collection of directory names. /// </summary> /// <param name="searchOption">Specifiy depth with <see cref="SearchOption"/></param> /// <param name="enumerateOptions">Options for enumerations</param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> public IEnumerable<string> EnumerateDirectoryPaths( SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return QuickIODirectory.EnumerateDirectoryPaths( PathInfo, searchOption, pathFormatReturn, enumerateOptions ); }
/// <summary> /// Search Exection /// </summary> /// <param name="uncDirectoryPath">Start directory path</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> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="filterType"><see cref="QuickIOFileSystemEntryType"/></param> /// <returns>Collection of path</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static IEnumerable <String> EnumerateSystemPaths(String uncDirectoryPath, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOFileSystemEntryType?filterType = null) { Contract.Requires(!String.IsNullOrWhiteSpace(uncDirectoryPath)); Contract.Ensures(Contract.Result <IEnumerable <String> >() != null); IEnumerable <QuickIOFileSystemEntry> entries = EnumerateFileSystemEntries(uncDirectoryPath, pattern, searchOption, enumerateOptions); // filter? if (filterType != null) { entries = entries.Where(entry => entry.Type == filterType); } // TODO: path format return(entries.Select(entry => entry.Path)); }
internal static Boolean TryParseShare(string path, QuickIOPathType shouldBe, out string serverName, out string shareName) { string[] pathElements; return(TryParseShare(path, shouldBe, out serverName, out shareName, out pathElements)); }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="path">The directory to search. </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">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383458(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateFilePaths( string path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return InternalEnumerateFileSystem.EnumerateSystemPaths( path, pattern, searchOption, enumerateOptions, pathFormatReturn, QuickIOFileSystemEntryType.File ); }
/// <summary> /// Returns an enumerable collection of directory names in a specified path in async context. /// </summary> /// <param name="path">The directory to search.</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> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> public static Task<IEnumerable<string>> EnumerateDirectoryPathsAsync( string path, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( () => EnumerateDirectoryPaths( new QuickIOPathInfo( path ), pattern, searchOption, pathFormatReturn, enumerateOptions ) ); }
/// <summary> /// Returns an enumerable collection of file names and directory names that match a search pattern in a specified path, and optionally searches subdirectories in a seperate task created by the default <see cref="TaskScheduler"/>. /// </summary> /// <param name="pathInfo">The directory to search. </param> /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory or should include all subdirectories.The default value is TopDirectoryOnly.</param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of file-system entries in the directory specified by path and that match the specified search pattern and option.</returns> /// <remarks><b>Requires .NET 4.0 or higher</b><br /><u>Warning:</u> parallel file system browsing on the same hard disk (HDD/SSD) will decrease performance. Use this only on stripped RAIDs or with network shares.</remarks> public static Task<IEnumerable<KeyValuePair<string, QuickIOFileSystemEntryType>>> EnumerateFileSystemEntryPathsAsync( QuickIOPathInfo pathInfo, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( () => EnumerateFileSystemEntryPaths( pathInfo, searchOption, pathFormatReturn, enumerateOptions ) ); }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="path">The directory to search. </param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383458(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateFilePaths( string path, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return EnumerateFilePaths( new QuickIOPathInfo( path ), searchOption, pathFormatReturn ); }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption">Specifiy depth with <see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options</param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> public IEnumerable <string> EnumerateFilePaths(String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None) { Contract.Requires(!String.IsNullOrWhiteSpace(pattern)); Contract.Ensures(Contract.Result <IEnumerable <string> >() != null); return(QuickIODirectory.EnumerateFilePaths(FullNameUnc, pattern, searchOption, pathFormatReturn, enumerateOptions)); }
/// <summary> /// Returns an enumerable collection of file names and directory names that match a search pattern in a specified path, and optionally searches subdirectories. /// </summary> /// <param name="path">The directory to search. </param> /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory or should include all subdirectories.The default value is TopDirectoryOnly.</param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <returns>An enumerable collection of file-system entries in the directory specified by path and that match the specified search pattern and option.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383459(v=vs.110).aspx</remarks> public static IEnumerable<KeyValuePair<string, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( string path, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return InternalQuickIO.EnumerateFileSystemEntryPaths( new QuickIOPathInfo( path ), searchOption, pathFormatReturn ); }
/// <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> /// Returns an enumerable collection of file names in a specified path in a seperate task created by the default <see cref="TaskScheduler"/>. /// </summary> /// <param name="path">The directory to search. </param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks><b>Requires .NET 4.0 or higher</b><br /><u>Warning:</u> parallel file system browsing on the same hard disk (HDD/SSD) will decrease performance. Use this only on stripped RAIDs or with network shares.</remarks> public static Task<IEnumerable<string>> EnumerateFilePathsAsync( string path, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( () => EnumerateFilePaths( new QuickIOPathInfo( path ), searchOption, pathFormatReturn ) ); }
/// <summary> /// Returns an enumerable collection of directory names in a specified path. /// </summary> /// <param name="path">The directory to search.</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">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383304(v=vs.110).aspx</remarks> public static IEnumerable <string> EnumerateDirectoryPaths(string path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(!String.IsNullOrWhiteSpace(pattern)); return(InternalEnumerateFileSystem.EnumerateSystemPaths(path, pattern, searchOption, enumerateOptions, pathFormatReturn, QuickIOFileSystemEntryType.Directory)); }
/// <summary> /// Returns an enumerable collection of directory names in a specified path. /// </summary> /// <param name="directoryInfo">The directory to search.</param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383304(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateDirectoryPaths( QuickIODirectoryInfo directoryInfo, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { return EnumerateDirectoryPaths( directoryInfo.PathInfo, searchOption, pathFormatReturn ); }
/// <summary> /// Determined all sub file system entries of a directory /// </summary> /// <param name="uncDirectoryPath">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> private static IEnumerable<KeyValuePair<String, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( String uncDirectoryPath, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular ) { // Match for start of search var currentPath = QuickIOPath.Combine( uncDirectoryPath, 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( uncDirectoryPath, win32Error ); } if ( EnumerationHandleInvalidFileHandle( uncDirectoryPath, enumerateOptions, win32Error ) ) { yield return new KeyValuePair<string, QuickIOFileSystemEntryType>( ); } } // Treffer auswerten do { // Ignore . and .. directories if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) ) { continue; } // Create hit for current search result var resultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName ); // Check for Directory if ( InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) ) { yield return new KeyValuePair<String, QuickIOFileSystemEntryType>( FormatPathByType( pathFormatReturn, resultPath ), QuickIOFileSystemEntryType.Directory ); // SubFolders?! if ( searchOption == SearchOption.AllDirectories ) { foreach ( var match in EnumerateFileSystemEntryPaths( resultPath, pattern, searchOption, enumerateOptions, pathFormatReturn ) ) { yield return match; } } } else { yield return new KeyValuePair<String, QuickIOFileSystemEntryType>( FormatPathByType( pathFormatReturn, resultPath ), QuickIOFileSystemEntryType.File ); } // Create new FindData object for next result win32FindData = new Win32FindData( ); } // Search for next entry while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) ); } }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="directoryInfo">The directory to search. </param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383458(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateFilePaths( QuickIODirectoryInfo directoryInfo, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return EnumerateFilePaths( directoryInfo.PathInfo, searchOption, pathFormatReturn, enumerateOptions ); }
/// <summary> /// Formats a path /// </summary> /// <param name="pathFormatReturn">Target format type</param> /// <param name="uncPath">Path to format</param> /// <returns>Formatted path</returns> private static string FormatPathByType( QuickIOPathType pathFormatReturn, string uncPath ) { return pathFormatReturn == QuickIOPathType.Regular ? QuickIOPath.ToRegularPath( uncPath ) : uncPath; }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="info">The directory to search. </param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383458(v=vs.110).aspx</remarks> public static IEnumerable<string> EnumerateFilePaths( QuickIOPathInfo info, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return InternalQuickIO.EnumerateFilePaths( info.FullNameUnc, searchOption, enumerateOptions, pathFormatReturn ); }
/// <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> /// Returns an enumerable collection of file names and directory names that match a search pattern in a specified path, and optionally searches subdirectories. /// </summary> /// <param name="pathInfo">The directory to search. </param> /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory or should include all subdirectories.The default value is TopDirectoryOnly.</param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of file-system entries in the directory specified by path and that match the specified search pattern and option.</returns> /// <remarks>http://msdn.microsoft.com/en-us/library/dd383459(v=vs.110).aspx</remarks> public static IEnumerable<KeyValuePair<string, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( QuickIOPathInfo pathInfo, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return InternalQuickIO.EnumerateFileSystemEntryPaths( pathInfo, searchOption, enumerateOptions, pathFormatReturn ); }
/// <summary> /// Returns an enumerable collection of file names in a specified path in a seperate task created by the default <see cref="TaskScheduler"/>. /// </summary> /// <param name="directoryInfo">The directory to search. </param> /// <param name="searchOption"><see cref="SearchOption"/></param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> /// <remarks><b>Requires .NET 4.0 or higher</b><br /><u>Warning:</u> parallel file system browsing on the same hard disk (HDD/SSD) will decrease performance. Use this only on stripped RAIDs or with network shares.</remarks> public static Task<IEnumerable<string>> EnumerateFilePathsAsync( QuickIODirectoryInfo directoryInfo, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { return NETCompatibility.AsyncExtensions.GetAsyncResult( () => EnumerateFilePaths( directoryInfo.PathInfo, searchOption, pathFormatReturn, enumerateOptions ) ); }
internal static Boolean TryGetServerAndShareNameFromLocation( string path, QuickIOPathType shouldBe, out string serverName, out string shareName ) { serverName = null; shareName = null; // Validate input if( String.IsNullOrWhiteSpace( path ) ) { return false; } if( shouldBe == QuickIOPathType.UNC ) { path = path.Substring( QuickIOPath.UncSharePathPrefix.Length ); } // try to found server and name string[ ] names = path.Trim( '\\' /*trim start and end */ ).Split( '\\' ); if( names.Length < 2 ) { // if less than two it is invalid return false; } serverName = names[ 0 ]; shareName = names[ 1 ]; return true; }