How to set switches in a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

How to set switches in a batch file

#1 Post by Rileyh » 07 Oct 2011 06:42

Hi,
I am making a batch program and the user is allowed to do inputs. The program will be called "List.bat" and the user should be able to type things such as "list.bat /v" or something like that.
I need help with setting the strings for the program.

Any help would be appreciated,
Rileyh

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to set switches in a batch file

#2 Post by aGerman » 07 Oct 2011 15:35

Code: Select all

if /i "%~1"=="/v" (
  REM your code here
)


Regards
aGerman

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: How to set switches in a batch file

#3 Post by Rileyh » 08 Oct 2011 01:10

aGerman,
Thanks for the post.
What am I supposed to put in the "REM your code here" section? (I mean, do I need to put code there for the above code or does is it just a statement, such as "@set var"?)

Regards,
Rileyh

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to set switches in a batch file

#4 Post by aGerman » 08 Oct 2011 08:54

Again replace the REM line with your code which should be executed if the batch file was called with /v as first argument.

Regards
aGerman

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: How to set switches in a batch file

#5 Post by Rileyh » 08 Oct 2011 21:06

aGerman,
Thank you for that. Out of interest, what is the "~" supposed to do?
I didn't mean for the switch to be called, moreso as an "extra command" (you would type it into cmd and then it would be activated and you would then place the extra switch on the command to do something else)

Thanks anyway,
Rileyh

Post Reply