2

How can I add an additional option to calling changeName.bat?

I want to configure -h (Help) to call changeName.bat -h

4444
  • 3,541
  • 10
  • 32
  • 43
  • 2
    Maybe check this http://stackoverflow.com/questions/3973824/windows-bat-file-optional-argument-parsing and tell if it helped you ;) – RCaetano Oct 07 '16 at 13:00

2 Answers2

1

You can directly gotothe arguments :

@echo off

If not "%~1"=="" goto:%~1 2>nul || Echo Error Invalid Argument

echo Here Your normal code without argument
exit/b

:-h
echo I'm In Help
exit/b


:-t
echo I'm in Test
exit/b

This is a very robust solution :

  • Invalid argument are directly treated without IF statement
  • Just create a new label to add a new parameter
  • You're code is well structured
SachaDee
  • 9,245
  • 3
  • 23
  • 33
0

A simple solution for your case:

@ECHO OFF

IF NOT "%1"=="" (
    IF "%1"=="-h" (
        ECHO This is the help text.
        GOTO end
    )
)

REM Add your instructions below and delete this line
ECHO Hello!

:end

HTH ;)

RCaetano
  • 642
  • 1
  • 8
  • 23