如何获取所有子文件夹及其文件 - UWP [英] How to get all sub folders and its files - UWP

查看:32
本文介绍了如何获取所有子文件夹及其文件 - UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在桌面上有一个名为 student_names 的固定文件夹.它包含子文件夹,每个子文件夹都包含它的文件.现在我想将这些子文件夹及其相应的文件名存储在一个数组列表中.怎么可能?

I have a fixed folder in desktop called student_names. it contains sub folders and each sub folders contains its files. Now I want to store those sub folders and its corresponding file names in an array list. how is it possible?

推荐答案

UWP 应用程序无法直接访问文件夹(应用程序文件夹除外),除非用户明确提供对文件夹的访问权限(至少一次).

UWP Applications cannot directly access a folder (except application folders) without the user explicitly providing access to the folder (atleast once).

因此,为了始终能够读取/写入特定文件夹,您需要首先要求用户选择特定文件夹.一旦用户选择了一个文件夹,您就可以将其保存到 FutureAccessList 中,这将为您提供一个令牌以直接访问该文件夹(无需用户干预)以备将来使用..

So in order to always be able to read/write to a specific folder you need to first ask user to select the specific folder. Once the user selects a folder you may save it to FutureAccessList which will provide you with a token to directly get access to the folder(without user intervention) for future use..

 var picker = new FolderPicker();
 picker.FileTypeFilter.Add("*");
 var folder = await picker.PickSingleFolderAsync();
 //add selected folder to FutureAccessList
StorageApplicationPermissions.FutureAccessList.AddOrReplace("futureAccessToken", folder);

从下一次启动(或您实现的任何逻辑)开始,您可以访问该文件夹并列出其内容

From next launch (or any logic that you implement) you can access the folder and list its contents

 var folder = await StorageApplicationPermissions.FutureAccessList.
                 GetFolderAsync("futureAccessToken");
 IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();

因此,您只需要提供对父文件夹(在您的情况下是 student_names)的访问权限,然后您就可以访问其子文件夹和文件.

So, you just need to provide access to the parent folder (which in your case is student_names) then you will be able to access its sub folders and files.

希望这有帮助..

这篇关于如何获取所有子文件夹及其文件 - UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆