示例#1
0
 private AFileInfo FindChildRecursive(string id, AFileInfo aFile)
 {
     if (aFile.Id == id)
     {
         return(aFile);
     }
     else if (aFile.IsFolder && aFile.Children.Any(f => f.Id == id))
     {
         return(aFile.Children.First(f => f.Id == id));
     }
     else
     {
         if (aFile.IsFolder && aFile.Children.Any(f => f.IsFolder))
         {
             foreach (var child in aFile.Children.Where(f => f.IsFolder))
             {
                 var data = FindChildRecursive(id, child);
                 if (data != null)
                 {
                     return(data);
                 }
             }
         }
     }
     return(null);
 }
示例#2
0
        public List <AFileInfo> GetAllChildren(AFileInfo parent = null, bool folderOnly = false)
        {
            if (parent == null)
            {
                parent = this;
            }
            var list = new List <AFileInfo>();
            IEnumerable <AFileInfo> children = new List <AFileInfo>();

            if (folderOnly)
            {
                children = parent.Children.Where(f => f.IsFolder);
            }
            else
            {
                children = parent.Children;
            }
            foreach (var child in children)
            {
                list.Add(child);
                list.AddRange(GetAllChildren(child, folderOnly));
            }
            return(list);
        }