/// <summary>
        /// Receives <see cref="QuickIODirectoryMetadata"/> of current directory
        /// </summary>
        /// <returns><see cref="QuickIODirectoryMetadata"/></returns>
        public static QuickIODirectoryMetadata EnumerateDirectoryMetadata( String path, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( path ) );
            Contract.Ensures( Contract.Result<QuickIODirectoryMetadata>() != null );

            return InternalEnumerateFileSystem.EnumerateDirectoryMetadata( path, 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 );
        }
        /// <summary>
        /// Returns an enumerable collection of files 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="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>
        public IEnumerable<QuickIOFileInfo> EnumerateFiles( String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( pattern ) );
            Contract.Ensures(Contract.Result<IEnumerable<QuickIOFileInfo>>() != null);

            return QuickIODirectory.EnumerateFiles( FullNameUnc, pattern, searchOption );
        }
        /// <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="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>
        /// Determined all sub system entries 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="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<Tuple<string, Win32FileSystemEntry>> EnumerateWin32FileSystemEntries( String path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( path ) );
            Contract.Ensures( Contract.Result<IEnumerable<Tuple<string, Win32FileSystemEntry>>>() != null );

            // Stack
            Stack<string> directoryPathStack = new Stack<string>();
            directoryPathStack.Push( path );

            while( directoryPathStack.Count > 0 )
            {
                string currentDirectory = directoryPathStack.Pop();

                foreach( Win32FileSystemEntry systemEntry in new Win32FileHandleCollection( QuickIOPath.Combine( currentDirectory, pattern ) ) )
                {
                    yield return new Tuple<string, Win32FileSystemEntry>( currentDirectory, systemEntry );

                    // Create hit for current search result
                    string resultPath = QuickIOPath.Combine( currentDirectory, systemEntry.Name );

                    // Check for Directory
                    if( searchOption == SearchOption.AllDirectories && systemEntry.IsDirectory )
                    {
                        directoryPathStack.Push( resultPath );
                    }
                }
            }
        }
        /// <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 );
        }
Example #8
0
        /// <summary>
        /// Returns an enumerable collection of files in a specified path.
        /// </summary>
        /// <param name="directoryInfo">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>
        /// <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 <QuickIOFileInfo> EnumerateFiles(QuickIODirectoryInfo directoryInfo,
                                                                   String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly,
                                                                   QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(directoryInfo != null);
            Contract.Requires(!String.IsNullOrWhiteSpace(pattern));

            return(EnumerateFiles(directoryInfo.FullNameUnc, pattern, searchOption, enumerateOptions));
        }
        /// <summary>
        /// Determined all sub 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="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<QuickIOFileSystemEntry> EnumerateFileSystemEntries( String uncDirectoryPath, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( uncDirectoryPath ) );
            Contract.Ensures( Contract.Result<IEnumerable<QuickIOFileSystemEntry>>() != null );

            return
                ( from pair in EnumerateWin32FileSystemEntries( uncDirectoryPath, pattern, searchOption, enumerateOptions )
                  let parentDirectory = pair.Item1
                  let win32Entry = pair.Item2
                  let fullpath = QuickIOPath.Combine( parentDirectory, win32Entry.Name )
                  select
                      new QuickIOFileSystemEntry( fullpath, win32Entry.FileSystemEntryType, win32Entry.Attributes, win32Entry.Bytes ) );
        }
        /// <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 );
        }
Example #11
0
        /// <summary>
        /// Determined all subfolders 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="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(string uncDirectoryPath,
                                                                                String pattern            = QuickIOPatterns.PathMatchAll,
                                                                                SearchOption searchOption = SearchOption.TopDirectoryOnly,
                                                                                QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(uncDirectoryPath));
            Contract.Ensures(Contract.Result <IEnumerable <QuickIODirectoryInfo> >() != null);

            // Stack
            Stack <string> directoryPathStack = new Stack <string>();

            directoryPathStack.Push(uncDirectoryPath);

            while (directoryPathStack.Count > 0)
            {
                string currentDirectory = directoryPathStack.Pop();

                foreach (Win32FileSystemEntry systemEntry in new Win32FileHandleCollection(QuickIOPath.Combine(currentDirectory, pattern)))
                {
                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine(currentDirectory, systemEntry.Name);

                    // Check for Directory
                    if (systemEntry.IsDirectory)
                    {
                        yield return(new QuickIODirectoryInfo(resultPath, systemEntry.FindData));

                        // SubFolders?!
                        if (searchOption == SearchOption.AllDirectories)
                        {
                            directoryPathStack.Push(resultPath);
                        }
                    }
                }
            }
        }
Example #12
0
 /// <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 );
 }
Example #13
0
        /// <summary>
        /// Determined metadata of directory
        /// </summary>
        /// <param name="path">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(String path, QuickIOEnumerateOptions enumerateOptions)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(path));
            Contract.Ensures(Contract.Result <QuickIODirectoryMetadata>() != null);

            IList <Win32FileSystemEntry> entries =
                new Win32FileHandleCollection(path).Cast <Win32FileSystemEntry>().ToList();

            //  TODO: search another solution instead of enumerator
            if (entries.Count > 1)
            {
                throw new InvalidOperationException("Found more than one entry to one specific path.");
            }

            return(EnumerateDirectoryMetadata(path, entries.ElementAt(0), enumerateOptions));;
        }
Example #14
0
 /// <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 );
 }
Example #15
0
 /// <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 );
 }
Example #16
0
 /// <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();
 }
Example #17
0
        /// <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));
        }
Example #18
0
 /// <summary>
 /// Returns an enumerable collection of directories 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="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 <QuickIODirectoryInfo> EnumerateDirectories(QuickIODirectoryInfo info, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
 {
     return(EnumerateDirectories(info.FullNameUnc, pattern, searchOption, enumerateOptions));
 }
Example #19
0
        /// <summary>
        /// Determined metadata of directory
        /// </summary>
        /// <param name="path">Path of the directory</param>
        /// <param name="fileSystemEntry"><see cref="Win32FileSystemEntry"/></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>
        private static QuickIODirectoryMetadata EnumerateDirectoryMetadata(String path, Win32FileSystemEntry fileSystemEntry, QuickIOEnumerateOptions enumerateOptions)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(path));
            Contract.Ensures(Contract.Result <QuickIODirectoryMetadata>() != null);

            // Results
            IList <QuickIOFileMetadata>      subFiles = new List <QuickIOFileMetadata>();
            IList <QuickIODirectoryMetadata> subDirs  = new List <QuickIODirectoryMetadata>();


            foreach (Win32FileSystemEntry systemEntry in new Win32FileHandleCollection(QuickIOPath.Combine(path, QuickIOPatterns.PathMatchAll)))
            {
                // Create hit for current search result
                var uncResultPath = QuickIOPath.Combine(path, systemEntry.Name);

                // if it's a file, add to the collection
                if (systemEntry.IsFile)
                {
                    subFiles.Add(new QuickIOFileMetadata(uncResultPath, systemEntry.FindData));
                }
                else
                {
                    subDirs.Add(EnumerateDirectoryMetadata(uncResultPath, systemEntry, enumerateOptions));
                }
            }
            return(new QuickIODirectoryMetadata(path, fileSystemEntry.FindData, subDirs, subFiles));
        }
 /// <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="directoryInfo">The directory to search. </param>
 /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></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>
 /// <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>
 /// <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<QuickIOPathInfo, QuickIOFileSystemEntryType>>> EnumerateFileSystemEntriesAsync( QuickIODirectoryInfo directoryInfo, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
 {
     return NETCompatibility.AsyncExtensions.GetAsyncResult( () => EnumerateFileSystemEntries( directoryInfo.PathInfo, searchOption, enumerateOptions ) );
 }
 /// <summary>
 /// Returns an enumerable collection of directories names in a specified path.
 /// </summary>
 /// <param name="info">The directory to search.</param>
 /// <param name="searchOption"><see cref="SearchOption"/></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<QuickIODirectoryInfo> EnumerateDirectories( QuickIOPathInfo info, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
 {
     return InternalQuickIO.EnumerateDirectories( info, searchOption, 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 ) );
 }
Example #23
0
        /// <summary>
        /// Determined all sub 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="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 <QuickIOFileSystemEntry> EnumerateFileSystemEntries(String uncDirectoryPath, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(uncDirectoryPath));
            Contract.Ensures(Contract.Result <IEnumerable <QuickIOFileSystemEntry> >() != null);

            return
                (from pair in EnumerateWin32FileSystemEntries(uncDirectoryPath, pattern, searchOption, enumerateOptions)
                 let parentDirectory = pair.Item1
                                       let win32Entry = pair.Item2
                                                        let fullpath = QuickIOPath.Combine(parentDirectory, win32Entry.Name)
                                                                       select
                                                                       new QuickIOFileSystemEntry(fullpath, win32Entry.FileSystemEntryType, win32Entry.Attributes, win32Entry.Bytes));
        }
Example #24
0
        /// <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));
        }
Example #25
0
 /// <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));
 }
Example #26
0
 /// <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 );
 }
Example #27
0
        /// <summary>
        /// Returns an enumerable collection of files 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="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>
        /// <example>
        /// <code>
        /// // Get subfiles
        /// IEnumerable&lt;QuickIOFileInfo&gt; allSubFiles = QuickIODirectory.EnumerateFiles( @"C:\temp\QuickIO", SearchOption.AllDirectories );
        ///
        /// foreach ( QuickIOFileInfo fileInfo in allSubFiles )
        /// {
        ///     Console.WriteLine( "File found: {0} Readonly: {1}", fileInfo.Path, fileInfo.IsReadOnly );
        /// }
        ///</code>
        /// </example>
        public static IEnumerable <QuickIOFileInfo> EnumerateFiles(string path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(path));
            Contract.Requires(!String.IsNullOrWhiteSpace(pattern));

            return(InternalEnumerateFileSystem.EnumerateFiles(path, pattern, searchOption, enumerateOptions));
        }
Example #28
0
        /// <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 ) );
            }
        }
Example #29
0
        /// <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));
        }
Example #30
0
        /// <summary>
        /// Determined metadata of directory
        /// </summary>
        /// <param name="uncDirectoryPath">Path of the directory</param>
        /// <param name="findData"><see cref="Win32FindData"/></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( String uncDirectoryPath, Win32FindData findData, QuickIOEnumerateOptions enumerateOptions )
        {
            // Results
            var subFiles = new List<QuickIOFileMetadata>( );
            var subDirs = new List<QuickIODirectoryMetadata>( );

            // Match for start of search
            var currentPath = QuickIOPath.Combine( uncDirectoryPath, QuickIOPatternConstants.All );

            // 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 ) )
                    {
                        return null;
                    }
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var uncResultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName );

                    #region File
                    // if it's a file, add to the collection
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        var fileMetaData = new QuickIOFileMetadata( uncResultPath, win32FindData );
                        subFiles.Add( fileMetaData );
                    }
                    #endregion
                    #region Directory
                    else
                    {
                        var dir = EnumerateDirectoryMetadata( uncResultPath, win32FindData, enumerateOptions );
                        subDirs.Add( dir );
                    }
                    #endregion
                    // Create new FindData object for next result

                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }

            return new QuickIODirectoryMetadata( uncDirectoryPath, findData, subDirs, subFiles );
        }
Example #31
0
 /// <summary>
 /// Returns an enumerable collection of directories 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="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>
 /// <example>
 /// <code>
 /// // Get subfolders
 /// IEnumerable&gt;QuickIODirectoryInfo&lt; allSubFolders = QuickIODirectory.EnumerateDirectories( @"C:\temp\QuickIO", SearchOption.AllDirectories );
 ///
 /// foreach ( QuickIODirectoryInfo directoryInfo in allSubFolders )
 /// {
 ///     Console.WriteLine( "Directory found: {0} Readonly: {1}", directoryInfo.Path, directoryInfo.IsReadOnly );
 /// }
 /// </code>
 /// </example>
 public static IEnumerable <QuickIODirectoryInfo> EnumerateDirectories(string path, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
 {
     return(InternalEnumerateFileSystem.EnumerateDirectories(path, pattern, searchOption, enumerateOptions));
 }
Example #32
0
        /// <summary>
        /// Determined all files 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="enumerateOptions">The enumeration options for exception handling</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(String uncDirectoryPath, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(uncDirectoryPath));
            Contract.Ensures(Contract.Result <IEnumerable <QuickIOFileInfo> >() != null);

            foreach (Win32FileSystemEntry systemEntry in new Win32FileHandleCollection(QuickIOPath.Combine(uncDirectoryPath, pattern)))
            {
                // Create hit for current search result
                var resultPath = QuickIOPath.Combine(uncDirectoryPath, systemEntry.Name);

                // Check for Directory
                if (systemEntry.IsFile)
                {
                    yield return(new QuickIOFileInfo(resultPath, systemEntry.FindData));
                }
                else if (/* it's already a directory here */ searchOption == SearchOption.AllDirectories)
                {
                    foreach (var match in EnumerateFiles(resultPath, pattern, searchOption, enumerateOptions))
                    {
                        yield return(match);
                    }
                }
            }
        }
 /// <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 );
 }
Example #34
0
        /// <summary>
        /// Handles the options to the fired exception
        /// </summary>
        private static bool EnumerationHandleInvalidFileHandle( string path, QuickIOEnumerateOptions enumerateOptions, int win32Error )
        {
            try
            {
                InternalQuickIOCommon.NativeExceptionMapping( path, win32Error );
            }
            catch ( Exception )
            {
                if ( ( enumerateOptions & QuickIOEnumerateOptions.SuppressAllExceptions ) == QuickIOEnumerateOptions.SuppressAllExceptions )
                {
                    return true;
                }

                throw;
            }
            return false;
        }
Example #35
0
        /// <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 ) );
            }
        }
Example #36
0
        /// <summary>
        /// Receives <see cref="QuickIODirectoryMetadata"/> of current directory
        /// </summary>
        /// <returns><see cref="QuickIODirectoryMetadata"/></returns>
        public static QuickIODirectoryMetadata EnumerateDirectoryMetadata(String path, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(path));
            Contract.Ensures(Contract.Result <QuickIODirectoryMetadata>() != null);

            return(InternalEnumerateFileSystem.EnumerateDirectoryMetadata(path, enumerateOptions));
        }
Example #37
0
        /// <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;
        }
Example #38
0
        /// <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));
        }
Example #39
0
        /// <summary>
        /// Determines the statistics of the given directory. This includes the number of files, folders and the total size in bytes.        
        /// </summary>
        /// <param name="path">Path to 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( String path, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            UInt64 fileCount = 0;
            UInt64 folderCount = 0;
            UInt64 totalSize = 0;

            // Match for start of search
            var currentPath = QuickIOPath.Combine( path, QuickIOPatternConstants.All );

            // 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 ( EnumerationHandleInvalidFileHandle( currentPath, enumerateOptions, win32Error ) )
                    {
                        return null;
                    }
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine( path, win32FindData.cFileName );

                    // if it's a file, add to the collection
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        fileCount++;
                        totalSize += win32FindData.CalculateBytes( ); win32FindData.CalculateBytes( );
                    }
                    else
                    {
                        folderCount++;
                        var result = GetDirectoryStatistics( resultPath, enumerateOptions );
                        {
                            folderCount += result.FolderCount;
                            fileCount += result.FileCount;
                            totalSize += result.TotalBytes;
                        }
                    }

                    // Create new FindData object for next result
                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }

            // Return result;
            return new QuickIOFolderStatisticResult( folderCount, fileCount, totalSize );
        }
        /// <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="pattern">Search pattern. Uses Win32 native filtering.</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="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>
        public IEnumerable <QuickIOFileSystemEntry> EnumerateFileSystemEntryInfos(String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(pattern));
            Contract.Ensures(Contract.Result <IEnumerable <QuickIOFileSystemEntry> >() != null);

            return(EnumerateFileSystemEntries(pattern, searchOption, enumerateOptions));
        }
Example #41
0
 /// <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>
        /// Returns an enumerable collection of files 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="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>
        public IEnumerable <QuickIOFileInfo> EnumerateFiles(String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(pattern));
            Contract.Ensures(Contract.Result <IEnumerable <QuickIOFileInfo> >() != null);

            return(QuickIODirectory.EnumerateFiles(FullNameUnc, pattern, searchOption));
        }
Example #43
0
 /// <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 );
 }
Example #44
0
 /// <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 );
 }
Example #45
0
        /// <summary>
        /// Determined all files 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="enumerateOptions">The enumeration options for exception handling</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( String uncDirectoryPath, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            // Match for start of search
            var currentPath = QuickIOPath.Combine( uncDirectoryPath, pattern );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstFileManaged( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid && EnumerationHandleInvalidFileHandle( uncDirectoryPath, 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( uncDirectoryPath, win32FindData.cFileName );

                    // Check for Directory
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        yield return new QuickIOFileInfo( resultPath, win32FindData );
                    }
                    else
                    {
                        // SubFolders?!
                        if ( searchOption == SearchOption.AllDirectories )
                        {
                            foreach ( var match in EnumerateFiles( resultPath, 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 ) );
            }
        }
Example #46
0
 /// <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>
 /// 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();
 }
Example #48
0
 /// <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 );
 }