public IEnumerable <IDirectory> Directories(string filter, SearchScope scope) { var path = new Path(filter); // if it's a rooted or it's a in the form of e.g. "C:" if (path.IsRooted || Regex.IsMatch(filter, "[A-Z]{1,3}:", RegexOptions.IgnoreCase)) { var directory = FileSystem.GetDirectory(path.Segments.First()); return(path.Segments.Count() == 1 ? new[] { directory } : directory.Directories(string.Join("\\", path.Segments.Skip(1) .DefaultIfEmpty("*") .ToArray()))); } var filterRegex = filter.Wildcard(); lock (ChildDirectories) { var immediateChildren = ChildDirectories.Where(x => x.Exists && filterRegex.IsMatch(x.Name)).Cast <IDirectory>(); return(scope == SearchScope.CurrentOnly ? immediateChildren.ToList() : immediateChildren .Concat(ChildDirectories.SelectMany(x => x.Directories(filter, scope))).ToList()); } }
public IEnumerable <IFile> Files(string filter, SearchScope searchScope) { lock (ChildFiles) lock (ChildDirectories) { var filterRegex = filter.Wildcard(); var immediateChildren = ChildFiles.Where(x => x.Exists && filterRegex.IsMatch(x.Name)).Cast <IFile>(); return(searchScope == SearchScope.CurrentOnly ? immediateChildren.ToList() : immediateChildren.Concat(ChildDirectories.SelectMany(x => x.Files(filter, searchScope))).ToList()); } }
/// <summary> /// Get all the files within all the dirs /// </summary> /// <returns></returns> public List <string> GetAllChildFiles() => ChildDirectories .SelectMany(x => x.ChildFiles) .ToList();