locked
How to perform a recursive search in windows store app?

    Question

  • Hi,

    I want to perform a search on particular folder recursively into all sub-folders inside that folder and return a list of all files and folders containing the query text.

    How do I go about achieving this? Are there any APIs for the same or do I have to manually iterate inside all subfolders and check?

    Thanks

    Friday, December 19, 2014 11:19 AM

Answers

  • QueryOptions fileOptions = new QueryOptions { FolderDepth = FolderDepth.Deep, UserSearchFilter="queryText" };

    StorageFolderQueryResult foldersquery = folder.CreateFolderQueryWithOptions(fileOptions);

    files = await foldersquery.Folder.GetFilesAsync();

    This should work

    There's also a StorageFileQueryResult that works very similar to StorageFolderQueryResult.  I'm not quite sure of the differences, but you can play around with that, too.


    Lee McPherson



    Monday, December 29, 2014 1:48 AM

All replies

  • StorageFolder.GetItemsAsync()

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Friday, December 19, 2014 12:47 PM
  • Start from an arbitrary top level folder, toss it in some List<StorageFolder>, call GetItemsAsync();

    the result for that call contains all folders and files in said folder.

    iterate the result with foreach. Check which item is a file, which is a folder.

    if a folder, toss said folder in the same List<StorageFolder>. If file, toss it in some List<StorageFile>

    Do this until you run out of folders in List<StorageFolder>.


    Saturday, December 20, 2014 5:40 PM
  • Thanks for your reply.

    I want to perform the search recursively. I want to navigate deep inside the hierarchy, not just at one folder level. It should be folder inside folder inside folder etc.

    Can this be done directly using some API or open source libraries and not manually iterating over the folders?

    Monday, December 22, 2014 4:16 AM
  • Sadly, this should be the API that is built in and technically does what you need it to do. But as you see in the following link, it doesn't quite do that

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/1cb12564-4e81-448f-93e3-2ad5ff7cde20/commonfilequeryorderbyname-doesnt-find-all-the-files-in-querried-folder?forum=wpdevelop

    Thursday, December 25, 2014 7:54 PM
  • QueryOptions fileOptions = new QueryOptions { FolderDepth = FolderDepth.Deep, UserSearchFilter="queryText" };

    StorageFolderQueryResult foldersquery = folder.CreateFolderQueryWithOptions(fileOptions);

    files = await foldersquery.Folder.GetFilesAsync();

    This should work

    There's also a StorageFileQueryResult that works very similar to StorageFolderQueryResult.  I'm not quite sure of the differences, but you can play around with that, too.


    Lee McPherson



    Monday, December 29, 2014 1:48 AM