Created
December 26, 2012 02:54
-
-
Save anaisbetts/4377491 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IObservable<Unit> CreateRecursive(string path) | |
{ | |
var paths = path.Split('\\'); | |
var firstFolderThatExists = Observable.Range(0, paths.Length - 1) | |
.Select(x => | |
StorageFolder.GetFolderFromPathAsync(String.Join("\\", paths.Take(paths.Length - x))) | |
.ToObservable() | |
.LoggedCatch(this, Observable.Empty<StorageFolder>())) | |
.Concat() | |
.Take(1); | |
return firstFolderThatExists | |
.Select(x => | |
{ | |
if (x.Path == path) return null; | |
return new { Root = x, Paths = path.Replace(x.Path + "\\", "").Split('\\')}; | |
}) | |
.SelectMany(x => | |
{ | |
if (x == null) return Observable.Return(default(StorageFolder)); | |
return x.Paths.ToObservable().Aggregate(x.Root, (acc, y) => acc.CreateFolderAsync(y).ToObservable().First()); | |
}) | |
.Select(_ => Unit.Default); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment