public IEnumerator <FileSyDirectoryInfo> GetEnumerator() { if (rootPath == null || !rootPath.Exists || rootDirectory.Value == null) { yield break; } IEnumerable <DirectoryInfo> matches = SafeEnumerable.Wrap(() => enumerateOptions.Option == SearchOption.AllDirectories && pattern == "*" ? rootPath.EnumerateDirectories(pattern, SearchOption.TopDirectoryOnly).ToArray() : rootPath.EnumerateDirectories(pattern, SearchOption.TopDirectoryOnly)); foreach (var directory in matches) { if (!parentDirectory.HasValue) { parentDirectory = Optional.Wrap(Try.Execute( () => rootPath.Parent == null ? null : new ManagedFileSyDirectoryInfo(rootPath.Parent), null)); } yield return(new ManagedFileSyDirectoryInfo(directory, parentDirectory)); } if (enumerateOptions.Option != SearchOption.AllDirectories) { yield break; } var subfolderMatches = pattern == "*" ? matches : SafeEnumerable.Wrap(() => rootPath.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)); foreach (var subfolder in subfolderMatches) { if (!enumerateOptions.EnumerateReparse && (subfolder.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) { continue; } var fileSystemInfos = new ManagedFileSyDirectoryEnumerable(subfolder, pattern, enumerateOptions, rootDirectory); foreach (var match in fileSystemInfos) { yield return(match); } } }
public IEnumerator <FileSyInfo> GetEnumerator() { if (rootPath == null || !rootPath.Exists || rootDirectory.Value == null) { yield break; } var fileMatches = SafeEnumerable.Wrap(() => rootPath.EnumerateFiles(pattern, SearchOption.TopDirectoryOnly)); foreach (var file in fileMatches) { if (!parentDirectory.HasValue) { parentDirectory = Optional.Wrap(Try.Execute( () => rootPath.Parent == null ? null : new ManagedFileSyDirectoryInfo(rootPath.Parent), null)); } yield return(new ManagedFileSyFileInfo(file, parentDirectory)); } if (enumerateOptions.Option == SearchOption.TopDirectoryOnly) { yield break; } var subfolders = SafeEnumerable.Wrap(() => rootPath.EnumerateDirectories(pattern, SearchOption.TopDirectoryOnly)); foreach (var subfolder in subfolders) { var subFolderInfo = new ManagedFileSyDirectoryInfo(subfolder, rootDirectory); yield return(subFolderInfo); if (!enumerateOptions.EnumerateReparse && (subfolder.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) { continue; } var fileSystemInfos = new ManagedFileSyFileSystemEnumerable(subfolder, pattern, enumerateOptions, rootDirectory); foreach (var entry in fileSystemInfos) { yield return(entry); } } }