user5525674
user5525674

Reputation: 921

Getting all files in UWP app folder

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.

Upvotes: 24

Views: 25484

Answers (2)

rubStackOverflow
rubStackOverflow

Reputation: 6163

var storageFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Assets");
var files = await storageFolder.GetFilesAsync();

https://learn.microsoft.com/en-us/uwp/api/windows.storage.applicationdata

Upvotes: 3

Romasz
Romasz

Reputation: 29792

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();

Upvotes: 48

Related Questions