Getting all files in UWP app folder

user5525674 picture user5525674 · Nov 16, 2015 · Viewed 22.6k times · Source

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.

Answer

Romasz picture Romasz · Nov 16, 2015

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