private IEnumerable <PathEntry> EnumerateFolder(DirectoryPath dsrcpath, string fsrcpath, int depth) { if (depth >= _searchDepth) { yield break; } foreach (var filepath in Directory.EnumerateFiles(fsrcpath)) { if (!filepath.ToLower().EndsWith(".txt") && !filepath.ToLower().EndsWith(".md")) { continue; } yield return(new PathEntry( filepath, dsrcpath, FilenameHelper.ConvertStringFromFilenameBack(Path.GetFileNameWithoutExtension(filepath)), new DateTimeOffset(new FileInfo(filepath).LastWriteTime), File.ReadAllText(filepath, _encoding))); } foreach (var dir in Directory.EnumerateDirectories(fsrcpath)) { var d = dsrcpath.SubDir(FilenameHelper.ConvertStringFromFilenameBack(Path.GetFileName(dir))); foreach (var item in EnumerateFolder(d, dir, depth + 1)) { yield return(item); } } }