Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Checking for a wildcard

Dec
238
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
 
Back
Top