3

In the regular .NET Framework, there are a number of methods for retrieving a subset of files in a directory based on a search pattern, for example DirectoryInfo.GetFiles(string searchPattern).

Is there a corresponding method for Windows Store applications? .NET for Windows Store apps does not contain the Directory or DirectoryInfo classes, and neither of the StorageFolder.GetFilesAsync overloads in the Windows API support search patterns.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114

1 Answers1

4

The Windows.Storage.Search namespace allows you to do file searches with patterns. Also, the Programmatic file search sample from Microsoft demonstrates how to use the api.

chue x
  • 18,573
  • 7
  • 56
  • 70
  • Thanks! Apparently the search patterns can be made very complex using the Advanced Query Syntax, but it is not obvious to me if I can also apply the "classic" file search patterns like `*hello*`, `?alid_name*.*` etc. in AQS. Are you able to expand on the subject? – Anders Gustafsson Jan 21 '13 at 13:47
  • @AndersGustafsson - Take a look at the `SearchButton_Click` function in the search sample in the Scenario1.xaml.cs file in the second link above. They use a `*` pattern in the search. I am not sure if `?` is supported, although it would be easy to find out. – chue x Jan 21 '13 at 13:51
  • Yes, they use the `*` pattern for the `FileTypeFilter`, but there is no explicit example of the `UserSearchFilter` (not in XAML nor in the code-behind file), which is primarily what I am aiming for. – Anders Gustafsson Jan 21 '13 at 14:02
  • I have made some initial tests, and it actually seems like `*` filtering is working OK, which should be enough for now. Again, thanks for the help. – Anders Gustafsson Jan 21 '13 at 14:17
  • Just a note to UWP developers today: Wildcards do not seem to be supported in UWP. – ShrimpCrackers Aug 25 '17 at 01:53