Page 1 of 1
Question about if statement
Posted: 08 Jun 2011 03:13
by jvuz
Hello,
I want to do this:
if ... and .... do ...
Is there a way to do this?
Jvuz
Re: Question about if statement
Posted: 08 Jun 2011 03:44
by Ed Dyreen
Maybe u should do some homework.
MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference
http://www.allenware.com/icsw/icswidx.htm
Re: Question about if statement
Posted: 08 Jun 2011 04:06
by jvuz
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
Re: Question about if statement
Posted: 08 Jun 2011 05:28
by renzlo
What are you trying to do? Maybe we can help.
Re: Question about if statement
Posted: 08 Jun 2011 06:03
by jvuz
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
Re: Question about if statement
Posted: 08 Jun 2011 06:27
by Ed Dyreen
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
)
)
Re: Question about if statement
Posted: 08 Jun 2011 06:33
by jvuz
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
Re: Question about if statement
Posted: 08 Jun 2011 14:34
by Cleptography
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.
Please do your homework before asking questions.
http://ss64.org/viewtopic.php?id=803Further 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.
Re: Question about if statement
Posted: 10 Jun 2011 06:21
by orange_batch
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
Re: Question about if statement
Posted: 10 Jun 2011 06:32
by jvuz
Thank you orrange_batch. i'll try it out.
Jvuz
Re: Question about if statement
Posted: 10 Jun 2011 06:37
by jvuz
Thanks,
it works that way
Re: Question about if statement
Posted: 10 Jun 2011 15:01
by orange_batch
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.