Menu

multiple search patterns?

2021-08-20
2021-08-24
  • Eric Keuchel

    Eric Keuchel - 2021-08-20

    Hi there
    do you have a way to use multiple search patterns ie (.txt|.jpg|*.dat)
    thanks!
    Eric

     
  • Opulos Inc.

    Opulos Inc. - 2021-08-21

    GetFiles(String path, String searchPattern = "*", ...);

    /// <param name="searchPattern">The search string to match against files in the path. Multiple can be specified separated by the pipe character.

     
  • Eric Keuchel

    Eric Keuchel - 2021-08-24

    Thank you! This worked
    out of curiosity, why doesn't the enumeratefiles function support this also?
    thanks
    Eric

     
  • Opulos Inc.

    Opulos Inc. - 2021-08-24

    There is some inconsistency there. The kernel32.dll FindFirstFileEx method doesn't support multiple filters, so the pipe separated filters was only added to GetFiles but not to EnumerateFiles.

    The issue with multiple filters is the possibility that the same file is hit by multiple filters. E.g. if there is a file called data.txt and two filters are specified data.*|*.txt then the EnumerateFiles would return data.txt twice. However, the GetFiles(...) method checks for duplicates.

    EnumerateFiles should probably support pipe separated filters, but come with a warning in the method description that the same file could be returned multiple times if the filename is matched by more than one search filter.

     

Log in to post a comment.