예제 #1
0
        public IEnumerable <Directory> 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
                                        .Cast <Directory>()
                                        .Where(x => x.Exists() && filterRegex.IsMatch(x.Name));

                return(scope == SearchScope.CurrentOnly
                                               ? immediateChildren.ToList()
                                               : immediateChildren
                       .Concat(ChildDirectories.SelectMany(x => x.Directories(filter, scope))).ToList());
            }
        }
예제 #2
0
 public IEnumerable <Directory> Directories()
 {
     lock (ChildDirectories)
     {
         return(ChildDirectories
                .Cast <Directory>()
                .Where(x => x.Exists()).ToList());
     }
 }