Example #1
0
        public static List <string> GetDirectoriesFromRootPath(string rootPath, string directorySearchPatterns = "", BackgroundWorker worker = null)
        {
            if (!Directory.Exists(rootPath))
            {
                return(null);
            }

            var searchPatterns = directorySearchPatterns?.Split('|') ?? new string[] { "" };

            List <string> directories = getDirectoriesFromPath(rootPath, worker) ?? new List <string>();

            directories = directories.Where(dir => StringServices.IsTextIncludingPatterns(dir, searchPatterns)).ToList();

            foreach (var directory in directories)
            {
                var recursiveYield = GetDirectoriesFromRootPath(directory, directorySearchPatterns, worker);
                directories = recursiveYield != null
                    ? directories.Concat(recursiveYield).ToList()
                    : null;
            }

            return(directories != null?directories.ToList() : null);
        }
Example #2
0
        public static List <string> ScanDirectory(string path, string fileSearchPatterns = "")
        {
            List <string> foundFiles     = null;
            var           searchPatterns = fileSearchPatterns?.Split('|') ?? new string[] { "" };

            try
            {
                foundFiles = new List <string>(Directory.GetFiles(path));
            }
            catch (UnauthorizedAccessException)
            {
                Console.WriteLine($"Insufficient rights to read all files in \"{path}\".");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Unknown error while reading a directory: {e.Message}");
            }

            foundFiles = foundFiles?.Where(file => StringServices.IsTextIncludingPatterns(file, searchPatterns)).ToList();

            return((foundFiles != null && foundFiles.Count > 0)
                ? foundFiles
                : null);
        }