public async static Task <StorageFolderWithPath> DangerousGetFolderWithPathFromPathAsync(string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null) { if (rootFolder != null) { var currComponents = GetDirectoryPathComponents(value); if (rootFolder.Path == value) { return(rootFolder); } else if (parentFolder != null && value.IsSubPathOf(parentFolder.Path)) { var folder = parentFolder.Folder; var prevComponents = GetDirectoryPathComponents(parentFolder.Path); var path = parentFolder.Path; foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path)) { folder = await folder.GetFolderAsync(component.Title); path = Path.Combine(path, folder.Name); } return(new StorageFolderWithPath(folder, path)); } else if (value.IsSubPathOf(rootFolder.Path)) { var folder = rootFolder.Folder; var path = rootFolder.Path; foreach (var component in currComponents.Skip(1)) { folder = await folder.GetFolderAsync(component.Title); path = Path.Combine(path, folder.Name); } return(new StorageFolderWithPath(folder, path)); } } if (parentFolder != null && !Path.IsPathRooted(value)) { // Relative path var fullPath = Path.GetFullPath(Path.Combine(parentFolder.Path, value)); return(new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(fullPath))); } else { return(new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(value))); } }
public async static Task <IList <StorageFolderWithPath> > GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue) { var queryOptions = new QueryOptions(); queryOptions.ApplicationSearchFilter = $"System.FileName:{nameFilter}*"; StorageFolderQueryResult queryResult = parentFolder.Folder.CreateFolderQueryWithOptions(queryOptions); return((await queryResult.GetFoldersAsync(0, maxNumberOfItems)).Select(x => new StorageFolderWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList()); }
public async static Task <IList <StorageFileWithPath> > GetFilesWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue) { return((await parentFolder.Folder.GetFilesAsync(CommonFileQuery.DefaultQuery, 0, maxNumberOfItems)) .Select(x => new StorageFileWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList()); }
public async static Task <StorageFile> DangerousGetFileFromPathAsync(string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null) { return((await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder)).File); }
public async static Task <StorageFolder> GetFolderFromPathAsync(string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null) { return((await GetFolderWithPathFromPathAsync(value, rootFolder, parentFolder)).Folder); }
public async static Task <StorageFileWithPath> GetFileWithPathFromPathAsync(string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null) { if (rootFolder != null) { var currComponents = GetDirectoryPathComponents(value); if (parentFolder != null && value.IsSubPathOf(parentFolder.Path)) { var folder = parentFolder.Folder; var prevComponents = GetDirectoryPathComponents(parentFolder.Path); var path = parentFolder.Path; foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path).SkipLast(1)) { folder = await folder.GetFolderAsync(component.Title); path = Path.Combine(path, folder.Name); } var file = await folder.GetFileAsync(currComponents.Last().Title); path = Path.Combine(path, file.Name); return(new StorageFileWithPath(file, path)); } else if (value.IsSubPathOf(rootFolder.Path)) { var folder = rootFolder.Folder; var path = rootFolder.Path; foreach (var component in currComponents.Skip(1).SkipLast(1)) { folder = await folder.GetFolderAsync(component.Title); path = Path.Combine(path, folder.Name); } var file = await folder.GetFileAsync(currComponents.Last().Title); path = Path.Combine(path, file.Name); return(new StorageFileWithPath(file, path)); } } try { var file = await parentFolder.Folder.GetFileAsync(value); var path = Path.Combine(parentFolder.Folder.Path, value); return(new StorageFileWithPath(file, path)); } catch { return(new StorageFileWithPath(await StorageFile.GetFileFromPathAsync(value))); } }