• 0

C# Windows Store enumerate folders or files


Question

Hello gang,

Making my first Windows Store app and I am attempting to be able to enumerate through the files and/or folders in the KnownFolders.MusicLibrary or other known folder.

I have this, but this does not get what I want.


var MusicFolders = Windows.Storage.KnownFolders.MusicLibrary.CreateFolderQuery();
[/CODE]

Clues?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0


var options = new QueryOptions(CommonFileQuery.OrderByMusicProperties);
var files = await KnownFolders.MusicLibrary.CreateFileQueryWithOptions(options).GetFilesAsync();[/CODE]

*should* give you a deep, flat list of all the files in the music library, using the search indexer.

If you want non indexed version, pass in "KnownFolders.MusicLibrary" to this

[CODE]
async static Task RecursiveCrawl(IStorageFolder folder)
{
var folders = await folder.GetFoldersAsync();
if (folders != null) foreach (var fol in folders) await RecursiveCrawl(fol);

var files = await folder.GetFilesAsync();
foreach (var fi in files)
{
// Do stuff
}
}
[/CODE]

Thanks to the runtime brokers restrictions however you won't get any hidden files returned, no matter what you do. So no folder.jpg 's coming out.

It's preferable to use the first because it's many leagues faster. Unfortunately though, for reasons I may never know, I've had a number of emails from users who have had the former query await forever. Probably a corrupt search index, but there's no way of you knowing that.

Link to comment
Share on other sites

This topic is now closed to further replies.