/// <summary> /// Internal function to get folders. /// </summary> /// <param name="folder">The folder.</param> /// <param name="searchPattern">The search pattern.</param> /// <param name="searchOption">The search option.</param> /// <returns>An enumerable representing the folders.</returns> private static IEnumerable<string> InternalGetFolders(AFolder folder, string searchPattern, SearchOption searchOption) { var folders = new List<string>(); var subFolders = folder.GetFolderNames(); foreach (var subFolder in subFolders) { if (Regex.IsMatch(subFolder, searchPattern)) folders.Add(subFolder); if (searchOption != SearchOption.TopDirectoryOnly) { var subFolderFolders = EnumerateFolders(subFolder, searchPattern, SearchOption.AllDirectories); foreach (var tmp in subFolderFolders) { if (Regex.IsMatch(tmp, searchPattern)) folders.Add(tmp); } } } return folders; }
/// <summary> /// Internal function to get file system entries. /// </summary> /// <param name="folder">The folder.</param> /// <param name="searchPattern">The search pattern.</param> /// <param name="searchOption">The search option.</param> /// <returns>An enumerable representing the file system entries.</returns> private static IEnumerable<string> InternalGetFileSystemEntries(AFolder folder, string searchPattern, SearchOption searchOption) { var filesAndFolders = new List<string>(); if (searchOption != SearchOption.SubDirectoriesOnly) { var topFiles = folder.GetFileNames(); foreach (var file in topFiles) { if (Regex.IsMatch(file, searchPattern)) filesAndFolders.Add(file); } var topFolders = folder.GetFileNames(); foreach (var topFolder in topFolders) { if (Regex.IsMatch(topFolder, searchPattern)) filesAndFolders.Add(topFolder); } } var folders = folder.GetFolderNames(); foreach (var subFolder in folders) { if (Regex.IsMatch(subFolder, searchPattern)) filesAndFolders.Add(subFolder); if (searchOption != SearchOption.TopDirectoryOnly) { var subFiles = EnumerateFileSystemEntries(subFolder, searchPattern, SearchOption.AllDirectories); foreach (var file in subFiles) { if (Regex.IsMatch(file, searchPattern)) filesAndFolders.Add(file); } } } return filesAndFolders; }