コード例 #1
0
        public async static Task <StorageFileWithPath> DangerousGetFileWithPathFromPathAsync
            (string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null)
        {
            if (rootFolder is not null)
            {
                var currComponents = GetDirectoryPathComponents(value);

                if (parentFolder is not null && value.IsSubPathOf(parentFolder.Path))
                {
                    var folder         = parentFolder.Item;
                    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 = PathNormalization.Combine(path, folder.Name);
                    }
                    var file = await folder.GetFileAsync(currComponents.Last().Title);

                    path = PathNormalization.Combine(path, file.Name);
                    return(new StorageFileWithPath(file, path));
                }
                else if (value.IsSubPathOf(rootFolder.Path))
                {
                    var folder = rootFolder.Item;
                    var path   = rootFolder.Path;
                    foreach (var component in currComponents.Skip(1).SkipLast(1))
                    {
                        folder = await folder.GetFolderAsync(component.Title);

                        path = PathNormalization.Combine(path, folder.Name);
                    }
                    var file = await folder.GetFileAsync(currComponents.Last().Title);

                    path = PathNormalization.Combine(path, file.Name);
                    return(new StorageFileWithPath(file, path));
                }
            }
コード例 #2
0
 public async static Task <BaseStorageFile> DangerousGetFileFromPathAsync
     (string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null)
 => (await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder)).Item;