Reputation: 1090
This sample only returns the top level files from a folder:
var myFiles = await tempFolder.GetFilesAsync();
But how do I get the files or folders recursively ? Here is the javascript answer, which is using QueryOptions, but that's not an option in C#
Javascript verison of this question
Upvotes: 1
Views: 691
Reputation: 1090
IMHO, it's not that intuitive and kind of confusing that the GetFilesAsync takes a CommonFileQuery enum, but their values not at all suggest their real meaning.
MSDN documents it, but still it can be confusing if you don't start with reading MSDN for every method. CommonFileQuery enumeration
These will return top level files only:
var myFiles = await tempFolder.GetFilesAsync();
var myFiles = await tempFolder.GetFilesAsync(CommonFileQuery.DefaultQuery);
While these other enum values will perform a recursive file listing, plus orders the list, so it's really does 2 things.
var myFilesRecursive = await tempFolder.GetFilesAsync(CommonFileQuery.OrderByName);
var myFilesRecursive = await tempFolder.GetFilesAsync(CommonFileQuery.OrderByDate);
Seems like you can only sort the list if you do a recursive (deep) query.
For me it didn't make much sense to implement it in this ways, hence putting it up here as a Q&A for others.
Something like this could be more useful and intuitive:
var myPreferredFileList = await tempFolder.GetFilesAsync(CommonFileQuerySort.OderByName, CommonFileQueryView.Deep);
Upvotes: 1