예제 #1
0
        /// <summary>
        /// Returns a list of files given a file search pattern.  Will also search sub-directories.
        /// </summary>
        /// <param name="searchPattern">Search pattern.  Can include a full or partial path and standard wildcards for the file name.</param>
        /// <param name="scope">The scope of the search.</param>
        /// <param name="baseDir">Base directory to use for partially qualified paths</param>
        /// <returns>An array of <c>FileInfo</c> objects for files matching the search pattern. </returns>
        public static IList<FileInfo> GetFiles(ParsedPath fileSpec, SearchScope scope)
        {
            ParsedPath rootPath = fileSpec.MakeFullPath();

            if (scope != SearchScope.DirectoryOnly)
            {
                List<FileInfo> files = new List<FileInfo>();

                if (scope == SearchScope.RecurseParentDirectories)
                    RecursiveGetParentFiles(rootPath, ref files);
                else
                    RecursiveGetSubFiles(rootPath, (scope == SearchScope.RecurseSubDirectoriesBreadthFirst), ref files);

                return files.ToArray();
            }
            else
            {
                return NonRecursiveGetFiles(rootPath);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns a list of directories given a file search pattern.  Will also search sub-directories and 
        /// parent directories.
        /// </summary>
        /// <param name="dirSpec">Search specification with with optional directory and wildcards</param>
        /// <param name="scope">The scope of the search. <see cref="SearchScope"/></param>
        /// <returns>An array of <c>DirectoryInfo</c> objects for files matching the search pattern. </returns>
        public static IList<DirectoryInfo> GetDirectories(ParsedPath dirSpec, SearchScope scope)
        {
            if (!dirSpec.HasFilename)
                throw new ArgumentException("Path does not have a filename");

            ParsedPath rootPath = dirSpec.MakeFullPath();

            if (scope != SearchScope.DirectoryOnly)
            {
                List<DirectoryInfo> dirs = new List<DirectoryInfo>();

                if (scope == SearchScope.RecurseParentDirectories)
                    RecursiveGetParentDirectories(rootPath, ref dirs);
                else
                    RecursiveGetSubDirectories(rootPath, (scope == SearchScope.RecurseSubDirectoriesBreadthFirst), ref dirs);

                return dirs.ToArray();
            }
            else
            {
                return NonRecursiveGetDirectories(rootPath);
            }
        }