Question about if statement

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jvuz
Posts: 38
Joined: 25 Feb 2011 03:37

Question about if statement

#1 Post by jvuz » 08 Jun 2011 03:13

Hello,

I want to do this:

if ... and .... do ...

Is there a way to do this?

Jvuz

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Question about if statement

#2 Post by Ed Dyreen » 08 Jun 2011 03:44

Maybe u should do some homework.

MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference :arrow:
http://www.allenware.com/icsw/icswidx.htm

jvuz
Posts: 38
Joined: 25 Feb 2011 03:37

Re: Question about if statement

#3 Post by jvuz » 08 Jun 2011 04:06

I already figured it out, it doesn't work.

I've done it differently, I started by defining a variable, then do the first check and if necessary change the variable, then do the second check and if necessary change again the variable.

thanks though,
Jvuz

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: Question about if statement

#4 Post by renzlo » 08 Jun 2011 05:28

What are you trying to do? Maybe we can help.

jvuz
Posts: 38
Joined: 25 Feb 2011 03:37

Re: Question about if statement

#5 Post by jvuz » 08 Jun 2011 06:03

In the beginning of the script I start by checking which version of OS it is by using the following:

Code: Select all

FOR /F "tokens=3 delims= " %%p IN ('ver ^| find /i "XP"') do (set ostype=XP)
FOR /F "tokens=3* delims= " %%q IN ('ver ^| find /i "6.0"') do (set ostype=Vista)
FOR /F "tokens=3* delims= " %%q IN ('ver ^| find /i "6.1"') do (set ostype=W7)


Then I check the bit

Code: Select all

if exist "c:\windows\syswow64" set bit=64
set bit=32


Now i need to check for both because of differences in the path

xp: c:\documents and settings
vista/W7: c:\users

32bit: c:\program files\
64bit: c:\program files (x86)\

I'll need to check if its
xp 32bit
xp 64bit
not xp (vista/W7) 32bit
not xp (vista/W7) 64bit

Jvuz

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Question about if statement

#6 Post by Ed Dyreen » 08 Jun 2011 06:27

Is this what u talk about ?

Code: Select all

if 1 equ 1 if 1 equ 1 (

      echo.inner if
)


Code: Select all

if /i ["%ostype%"] equ ["WinXP"] (

   echo.outer if
   if exist "c:\documents and settings" (

      echo.inner if
   )
)

jvuz
Posts: 38
Joined: 25 Feb 2011 03:37

Re: Question about if statement

#7 Post by jvuz » 08 Jun 2011 06:33

I haven't test that one, because at the end I could do it via a vbs script which didn't need to check out those things.

jvuz

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Question about if statement

#8 Post by Cleptography » 08 Jun 2011 14:34

If you do it in vbscript and now batch you are down grading.
Take a porsche and trade it in for a volvo makes no sense. :roll:
Please do your homework before asking questions. :wink:
http://ss64.org/viewtopic.php?id=803
Further more wmic is your friend learn how to use it, and if that fails
learn the registry and the reg command so you can just read the keys.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Question about if statement

#9 Post by orange_batch » 10 Jun 2011 06:21

Both of you, would be obliged if you were less obnoxious.

jvuz, the simple answer to your original question is as Ed described in his second response.

if ... and ... (and ... etc) do

Code: Select all

if %num1%==1 if %num2%==2 (

)

jvuz
Posts: 38
Joined: 25 Feb 2011 03:37

Re: Question about if statement

#10 Post by jvuz » 10 Jun 2011 06:32

Thank you orrange_batch. i'll try it out.

Jvuz

jvuz
Posts: 38
Joined: 25 Feb 2011 03:37

Re: Question about if statement

#11 Post by jvuz » 10 Jun 2011 06:37

Thanks,

it works that way

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Question about if statement

#12 Post by orange_batch » 10 Jun 2011 15:01

Welcome as always. :)

You can handle OR logic by watching your grouping of multiple IF conditions, and using the ELSE statement. Two small examples:

Code: Select all

if %num1%==1 if %num2%==2 (

) else if %num3%==3 (

) else (

)

If %num1%==1:
If %num2%==2, do first code, else if %num3%==3, do second code, else do third code.

Code: Select all

if %num1%==1 (
if %num2%==2 (

) else if %num3%==3 (

) else (

)) else (

)

If %num1%==1 (else do last code):
If %num2%==2, do first code, else if %num3%==3, do second code, else do third code.

Post Reply