Skip to content

Instantly share code, notes, and snippets.

@ionoy
Created March 9, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionoy/9453030 to your computer and use it in GitHub Desktop.
Save ionoy/9453030 to your computer and use it in GitHub Desktop.
static IObservable<FileInfo> GetFiles(DirectoryInfo root,
Func<FileInfo, bool> fileFilter,
Func<DirectoryInfo, bool> directoryFilter,
IScheduler scheduler = null)
{
scheduler = scheduler ?? Scheduler.Default;
return Observable.Create<FileInfo>(obs => {
Action<DirectoryInfo, Action<DirectoryInfo>> iterator = (dir, self) => {
foreach (var file in dir.GetFiles().Where(fileFilter))
obs.OnNext(file);
foreach (var childDir in dir.GetDirectories().Where(directoryFilter))
self(childDir);
};
return scheduler.Schedule(root, iterator);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment