Batch file ignoring IF statement

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lionround
Posts: 2
Joined: 20 Nov 2015 09:12

Batch file ignoring IF statement

#1 Post by lionround » 20 Nov 2015 09:20

I am relativly new to batch files, but here goes. I am trying to create directories and subs dependent on user input. The location will be L:\Public\Cases\Civil\Brackstone. There is a subdirectory entitled Restricted Cases. This is for what is known as "Bivens" cases. So the user input is whether or not it is a Bivens case determines which directory the new directories and subs are created in. Well here goes.

Code: Select all

@ECHO OFF
cd L:\

SET /P uname2=Please enter Your Case name (example John Doe v. US):
SET /P caseno=Please enter USA Case Number in the following format "15-XXXXX":
SET /P Bivens=Is this a Bivens case  Y or N?:

REM This is the part that isn't working. It's ignoring the If statement
If Bivens=N goto :BivensN

REM This is the section that makes the structure for Bivens cases
CD "L:\Public\Cases\Civil\Brackstone\Restricted Cases"
 MD "L:\Public\Cases\Civil\Brackstone\Restricted Cases\%uname2% %caseno%"
CD  "L:\Public\Cases\Civil\Brackstone\Restricted Cases\%uname2% %caseno%"
md Agency
md "Attorney Notes"

:BivensN
MD "L:\Public\Cases\Civil\Brackstone\%uname2% %caseno%"
CD "L:\Public\Cases\Civil\Brackstone\%uname2% %caseno%"

 REM This creates folders for the common structure of the non-Bivens cases.
:Civil
CD  "L:\Public\Cases\Civil\Brackstone\%uname2% %caseno%"
md Agency
md "Attorney Notes"

:End

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch file ignoring IF statement

#2 Post by Squashman » 20 Nov 2015 10:54

Not ignoring it at all. You are not referencing your variable correctly. You need to use percent symbols to reference the variable and you need to use TWO equal signs.

Code: Select all

If /I %Bivens%==N goto :BivensN

lionround
Posts: 2
Joined: 20 Nov 2015 09:12

Re: Batch file ignoring IF statement

#3 Post by lionround » 20 Nov 2015 10:59

Squashman, Thank you so much. Worked like a charm.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch file ignoring IF statement

#4 Post by Squashman » 20 Nov 2015 11:48

Your welcome and Welcome to the Dostips forum. Hope you stick around. Some of the best batch file coders help on this site. You can learn a lot here.

Post Reply