获取UWP应用文件夹中的所有文件 [英] Getting all files in UWP app folder

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

问题描述

对于UWP,很容易将应用程序本地文件夹中的所有文件获取为:

For UWP, it is easy to get all files in the app local folder as:

IReadOnlyList< StorageFile>文件=等待ApplicationData.Current.LocalFolder.GetFilesAsync();

您现在可以在文件列表上进行迭代甚至可以获取有关单个文件的更多信息。

You can now iterate on the files list and even get further info on individual files.

例如,我想为app文件夹使用类似的全文件获取器,请考虑 / Assets 文件夹,用于存储应用程序 *。png 文件。
具有已知名称的单个文件没有问题;我可以很容易地将其称为:

I would like a similar all-file-getter for an app folder, for instance, consider the /Assets folder where app *.png files are stored. Single file with a known name is no problem; I can refer to it quite easily as:

StorageFile.GetFileFromApplicationUriAsync(new Uri(@ ms-appx:/// Assets / StoreLogo。 png))

因此,我的问题是,获取应用程序文件夹中的所有文件是否存在类似的事情,例如 /资产文件夹?从逻辑上讲,它应该类似于 StorageFile.GetFilesFromApplicationFolderUriAsync(new Uri(@ ms-appx:/// Assets)),但不知道是否与上面显示的LocalFolder等效

My question is, therefore, is there a similar thing for getting all files in an app folder, such as /Assets folder? Logically, it should be something like StorageFile.GetFilesFromApplicationFolderUriAsync(new Uri(@"ms-appx:///Assets")) but unaware if an equivalent of the LocalFolder shown above exists.

推荐答案

您可以使用 Package.InstalledLocation 。因此,您的代码如下所示:

You can access you installation folder by using Package.InstalledLocation. Therefore your code can look like this:

StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder assets = await appInstalledFolder.GetFolderAsync("Assets");
var files = await assets.GetFilesAsync();

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

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