1.

Solve : disallow wildcards with the 'set' command?

Answer»

I HOPE one of you BRAINY folk can help. I've written a rather lengthy batch file and all works brilliantly, however as it involves deleting and renaming server based profiles based on user input I can't risk it allowing them to input wildcards otherwise they could technically have the ability to cause quite a bit of damage. So, basically all I need is a way of trapping user input of wildcards (eg * and ?) via a 'set /p' command... any ideas? Is there a way of saying:
if %input% contains "*" goto...
Would it be like this? Break it into little steps.

  • Get the user input.
  • Scan for certain symbols.
  • If found, chide the user and start over.
  • Otherwise all OK.
Is that too hard?You can use this little snippet as a template to integrate with your own code:

Code: [SELECT]@echo off
set /p var=Enter Data:
echo %var% | find "*"
if not errorlevel 1 echo Wildcard present

The operative instruction is checking the errorlevel for zero (not 1) indicating there is a wildcard in the user input. By trapping the data this way you can bring your batch file in for a gentle landing rather than SLAMMING into the mountain.

Good luck. Thanks for the replies and PM's chaps/chapettes. Sidewinders solution is the one I've used for it's SIMPLICITY. So simple yet works a treat (I think I was trying to overcomplicate things ) Thanks again!


Discussion

No Comment Found