Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all files in UWP app folder

Tags:

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

IReadOnlyList<StorageFile> files = await ApplicationData.Current.LocalFolder.GetFilesAsync();

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

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"))

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.

like image 331
user5525674 Avatar asked Nov 16 '15 19:11

user5525674


1 Answers

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(); 
like image 85
Romasz Avatar answered Oct 04 '22 21:10

Romasz