1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Checking for a wildcard

Discussion in 'T&T - Functions' started by mikea, Aug 15, 2013.

  1. mikea

    Joined:
    Dec 7, 2009
    Messages:
    210
    Likes Received:
    2
    I made a user-defined function for this (created when TCC starts).

    Code:
    HasWildard=%@if[%1 =~ [*?] == 1,1,0]
    A simple regex comparison (via "=~") is wrapped in an %@if[] function. This might seem like a bit of overkill but I like having functions whose names tell me what they do.

    For anyone who isn't using regular expressions yet: %1 =~ [*?] means: compare the supplied string ("%1") in the function against "[*?]", which means EITHER a single * OR a single ?. If either one matches, the surrounding %@if[] function returns 1 — likewise, if the string contains BOTH * and ?. If there's no match, %@if[] returns 0.

    Example in a batch file, in which I want to stop processing if the first argument on the command line contains 1 or more wildcard(s):

    Code:
    iff %@HasWildcard[%1] == 1 then
      echo Error: This script doesn't support wildcards in the filename.
      CANCEL
    endiff
     

Share This Page