I want to get all files in a folder and its sub folders. but a flat query like this:
var allFiles = await myFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName);
throws a ArgumentException
exception:
A first chance exception of type 'System.ArgumentException' occurred
Additional information: Value does not fall within the expected range.
before I query subfolders one by one, isn't there any other way?
MSDN says that you get
System.ArgumentException
if:https://msdn.microsoft.com/en-us/library/windows/apps/BR211591.aspx
That is strange! Looks like a bug in GetFilesAsync method with all CommaonFileQuery options except
DefaultQuery
. It is working fine with DefaultQuery.Hope this helps!
Use
CommonFileQuery.OrderByName
This is a deep query too so the result will contain all of files from all of subfolders AND IT WORKS! ;)I had the same problem, solved it by preloading file paths recursively:
No idea why downvoted, there is no other way to get full filelist in WP8.1. MSFT for some strange reason corrupts its apis from version to version. Some of calls now returns "not implemented".
You want all the files and folder which are a descendent of the root folder, not just the shallow enummeration. For most folders the only way to enumerate all the contents and its subfolders content is:
StorageFolder.GetFilesAsync()
for the filesStorageFolder.GetFoldersAsync()
to retrieve the all the subfoldersThere is a workaround for this if you are looking for a particular type of media. The instructions are here. These few combinations of locations and CommonFile/FolderQuery options will give a device deep search for media and return the ordered results.