获取 UWP 应用文件夹中的所有文件 [英] Getting all files in UWP app folder
问题描述
对于 UWP,很容易获取应用程序本地文件夹中的所有文件:
For UWP, it is easy to get all files in the app local folder as:
IReadOnlyList
您现在可以对文件列表进行迭代,甚至可以获取有关单个文件的更多信息.
You can now iterate on the files list and even get further info on individual files.
我想要一个类似的应用程序文件夹的所有文件获取器,例如,考虑存储应用程序 *.png 文件的 /Assets 文件夹.具有已知名称的单个文件没有问题;我可以很容易地将其称为:
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"))
因此,我的问题是,是否有类似的方法可以获取应用文件夹(例如 /Assets 文件夹)中的所有文件?从逻辑上讲,它应该类似于 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屋!