IEnumerable <DiscUtils.DiscFileInfo> IterateFilesystem(int partitionNumber) { IEnumerable <DiscUtils.DiscFileInfo> IterateSubdir(DiscUtils.DiscDirectoryInfo subdir) { foreach (var dir in subdir.GetDirectories()) { foreach (var subfile in IterateSubdir(dir)) { yield return(subfile); } } var files = subdir.GetFiles(); foreach (var f in files) { yield return(f); } } PartitionTable disk = OpenDisk(); if (disk == null) { Debug.WriteLine("IterateFilesystem: Failed to open disk"); yield break; } else if (disk.Partitions.Count - 1 < partitionNumber) { Debug.WriteLine($"IterateFilesystem: Partition {partitionNumber} does not exist"); yield break; } using (var fsStream = disk.Partitions[partitionNumber].Open()) { var partitionStream = GetPatchedNtfsPartitionStream(fsStream); NtfsFileSystem fs = new DiscUtils.Ntfs.NtfsFileSystem(partitionStream); foreach (var file in IterateSubdir(fs.Root)) { yield return(file); } fs.Dispose(); partitionStream.Dispose(); } }