#1 22 Oct 2005 20:55

butik
Member
Registered: 22 Oct 2005
Posts: 2

CMD File question

How do I test for /? or ? or -?  within a cmd file?

The IF treats it as a wildcard and does not permit it.

if [%1]==[/?] - will not work.

Any ideas?...

Thanks

Offline

#2 24 Oct 2005 18:59

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,011
Website

Re: CMD File question

You can use an IF statement like this
if [%1]==[/?] echo Help Requested
but it will only work for the first parameter
e.g. myscript /? but not myscript abc 123 /?

The following will display help for a ? anywhere on the command line

@echo off
set _params=%*
::convert a ? into the text string "found_help"
set _found=%_params:*?=found_help%
:: Now test for that string (in the first 10 chars)
if [%_found:~0,10%]==[found_help] echo Help Requested

Offline

#3 25 Oct 2005 19:21

butik
Member
Registered: 22 Oct 2005
Posts: 2

Re: CMD File question

thanks, it helps a lot

Offline

Board footer

Powered by FluxBB