public async Task <List <NavItem> > GetNavItemsAsync(DirectoryInfo scanDirectory, List <Folder> parentFolders) { List <NavItem> navItems = new List <NavItem>(); var test = scanDirectory .GetDirectories() .Where(x => _directoryScanRegex.IsMatch(x.Name)); foreach (DirectoryInfo directory in scanDirectory .GetDirectories() .Where(x => _directoryScanRegex.IsMatch(x.Name))) { Folder folder = new Folder(directory.Name); List <Folder> navItemparentFolders = parentFolders.ToList(); navItemparentFolders.Add(folder); FileInfo pageFile = directory.GetFiles(Markdown.Filename, SearchOption.TopDirectoryOnly).FirstOrDefault(); if (pageFile != null) { NavItem navItem = new NavItem(await GetNavItemDisplayNameAsync(string.Join(Separator.Path, navItemparentFolders.Select(x => x.DirectoryName)), folder.VirtualName), string.Join(Separator.Path, navItemparentFolders.Select(x => x.VirtualName)), folder.SequenceNumber); (await GetNavItemsAsync(directory, navItemparentFolders)) .ForEach(x => navItem.AddChild(x)); navItems.Add(navItem); } } return(navItems); }