Compartir a través de


2.1.4.4 Algorithm for Determining if a FileName Is in an Expression

The inputs for this algorithm are:

  • FileName: A Unicode string containing the file name string that is being matched. Filename cannot contain any wildcard characters.

  • Expression: A Unicode string containing the regular expression that's being matched with FileName.

  • IgnoreCase: A Boolean value indicating whether the match is case insensitive (TRUE) or case sensitive (FALSE).

This algorithm returns TRUE if FileName matches Expression, and FALSE if it does not.

Pseudocode for the algorithm is as follows:

  • Part 1 -- Handle Special Case Optimizations

  • If FileName is empty and Expression is not, the routine returns FALSE.

  • If Expression is empty and FileName is not, the routine returns FALSE.

  • If both Expression and FileName are empty, the routine returns TRUE.

  • If the Expression is the wildcard "*" or "*.*", the FileName matches the Expression and the routine returns TRUE.

  • If the first character in the Expression is wildcard "*" and the rest of the expression does not contain any wildcard characters (as specified in 2.1.4.3), then the remaining expression is compared against the tail end of the FileName. If the comparison succeeds then the routine returns TRUE.

  • Part 2 -- Match Expression with FileName

  • The FileName is string compared with Expression using the following wildcard rules:

    • * (asterisk) Matches zero or more characters.

    • ? (question mark) Matches a single character.

    • DOS_DOT (" quotation mark) Matches either a period or zero characters beyond the name string.

    • DOS_QM (> greater than) Matches any single character or, upon encountering a period or end of name string, advances the expression to the end of the set of contiguous DOS_QMs.

    • DOS_STAR (< less than) Matches zero or more characters until encountering and matching the final . in the name.