Question about if statement
Moderator: DosItHelp
Question about if statement
Hello,
I want to do this:
if ... and .... do ...
Is there a way to do this?
Jvuz
I want to do this:
if ... and .... do ...
Is there a way to do this?
Jvuz
Re: Question about if statement
Maybe u should do some homework.
MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference
http://www.allenware.com/icsw/icswidx.htm
MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference
http://www.allenware.com/icsw/icswidx.htm
Re: Question about if statement
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
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
What are you trying to do? Maybe we can help.
Re: Question about if statement
In the beginning of the script I start by checking which version of OS it is by using the following:
Then I check the bit
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
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
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
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
jvuz
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: Question about if statement
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=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.
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=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.
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Question about if statement
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
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 (
)
Re: Question about if statement
Thank you orrange_batch. i'll try it out.
Jvuz
Jvuz
Re: Question about if statement
Thanks,
it works that way
it works that way
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Question about if statement
Welcome as always.
You can handle OR logic by watching your grouping of multiple IF conditions, and using the ELSE statement. Two small examples:
If %num1%==1:
If %num2%==2, do first code, else if %num3%==3, do second code, else do third code.
If %num1%==1 (else do last code):
If %num2%==2, do first code, else if %num3%==3, do second code, else do third code.
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.