public static async Task <bool> FolderExists(this StorageFolder folder, string folderPath) { if (String.IsNullOrEmpty(folderPath)) { return(true); } var firstPart = Paths.RootFolderName(folderPath); if (await folder.ContainsFolderAsync(firstPart)) { var subFolder = await folder.GetFolderAsync(firstPart); var tail = Paths.DropRoot(folderPath, firstPart); return(await subFolder.FolderExists(tail)); } else { return(false); } }
/// <summary> /// FP in C#. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="folder"></param> /// <param name="filePath"></param> /// <param name="filesCombinator"></param> /// <param name="notFound"></param> /// <returns></returns> private static async Task <T> InspectFilePath <T>(this StorageFolder folder, string filePath, Func <IReadOnlyList <StorageFile>, Func <Func <StorageFile, bool>, T> > filesCombinator, T notFound = default(T)) { var fileName = Paths.FileNameOf(filePath); var firstPart = Paths.RootFolderName(filePath); if (firstPart == fileName) { var files = (await folder.GetFilesAsync()); return(filesCombinator(files)(file => file.Name == fileName)); } if (await folder.ContainsFolderAsync(firstPart)) { var subFolder = await folder.GetFolderAsync(firstPart); var tail = Paths.DropRoot(filePath, firstPart); return(await subFolder.InspectFilePath(tail, filesCombinator, notFound)); } else { return(notFound); } }