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 <IDirectory> Directories() { lock (ChildDirectories) { return(ChildDirectories.Where(x => x.Exists).Cast <IDirectory>().ToList()); } }