![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Batch: if statement I cannot find a BATCH scripting groups, was post in other group. Hoping I will get quick respond here because this group is targeting developers. When I execute this batch script with two prompts set to N. What am I doing wrong that it's entering the second "if statement"? Result: Enter (Y/N) N Enter2 (Y/N) N Msg 1 C_PATH exist Should not be here! @SET OVERWRITE=N @SET /P OVERWRITE="Enter (Y/N) " @SET C_PATH=C:\Windows :: BEGIN @IF "%OVERWRITE%" == "Y" ( @ECHO Hey %USERNAME% @ECHO Got IN overwrite @IF EXIST %C_PATH% ( @ECHO %C_PATH% exist ) @IF "A" == "A" ( @ECHO Hello!! ) @ECHO Should not display this message! ) @SET COMPILE=N @SET C_OVERWRITE=N @SET /P COMPILE="Enter2 (Y/N) " @IF "%COMPILE%" == "Y" ( @ECHO Hey2 %USERNAME% :: Check if directory is already exist @IF EXIST %C_PATH% ( @ECHO %C_PATH% exist @SET /P C_OVERWRITE="Overwrite %C_PATH% [Y/N] " ) :: Ask for overwrite @IF "%C_OVERWRITE%" == "Y" ( @ECHO C overwrite ) @ECHO Msg 1 @IF EXIST %C_PATH% ( @ECHO C_PATH exist ) @ECHO Should not be here! ) |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Batch: if statement "Slickuser" <slick.users@newsgroup> wrote in message news:36ec619e-29fd-4726-a702-a3c13605a814@newsgroup Quote: >I cannot find a BATCH scripting groups, was post in other group. > > Hoping I will get quick respond here because this group is targeting > developers. > > > > When I execute this batch script with two prompts set to N. > What am I doing wrong that it's entering the second "if statement"? - Having an @ at the start of each line is distracting. Use a single "@echo off" at the beginning instead. - Surrounding your == signs with spaces can cause trouble. Get rid of them! - Setting variables inside a multi-line statement (i.e. a statement that starts with a bracket and extends over several lines) does not work the way you use it, because multi-line statements are scanned and interpreted just once and *as a single line*. To make it work, you must force a rescan, using the syntax below and surrounding rescanned variables with exclamation marks instead of percentage signs. - There is an extremely active batch file newsgroup: alt.msdos.batch.nt. @echo off SetLocal EnableDelayedExpansion SET OVERWRITE=N SET /P OVERWRITE="Enter (Y/N) " SET C_PATH=C:\Windows :: BEGIN IF "%OVERWRITE%"=="Y" ( ECHO Hey %USERNAME% ECHO Got IN overwrite IF EXIST %C_PATH% ECHO %C_PATH% exist IF "A"=="A" ECHO Hello!! ECHO Should not display this message! ) SET COMPILE=N SET C_OVERWRITE=N SET /P COMPILE="Enter2 (Y/N) " IF "%COMPILE%"=="Y" ( ECHO Hey2 %USERNAME% :: Check if directory is already exist IF EXIST %C_PATH% ( ECHO %C_PATH% exist SET /P C_OVERWRITE="Overwrite %C_PATH% [Y/N] " ) :: Ask for overwrite IF "%C_OVERWRITE%" == "Y" ECHO C overwrite ECHO Msg 1 IF EXIST !C_PATH! ECHO C_PATH exist ECHO Should not be here! ) |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Batch: if statement "Pegasus [MVP]" <news@newsgroup> wrote in message news:utNuFsjSKHA.1236@newsgroup Quote: > > "Slickuser" <slick.users@newsgroup> wrote in message > news:36ec619e-29fd-4726-a702-a3c13605a814@newsgroup Quote: >>I cannot find a BATCH scripting groups, was post in other group. >> >> Hoping I will get quick respond here because this group is targeting >> developers. >> >> >> >> When I execute this batch script with two prompts set to N. >> What am I doing wrong that it's entering the second "if statement"? > Your batch file needs some improvements: > - Having an @ at the start of each line is distracting. Use a single > "@echo off" at the beginning instead. > - Surrounding your == signs with spaces can cause trouble. Get rid of > them! EQU - equal NEQ - not equal LSS - less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal These need to be separated from the operands, which makes things easier to read. Quote: > - Setting variables inside a multi-line statement (i.e. a statement that > starts with a bracket and extends over several lines) does not work the > way you use it, because multi-line statements are scanned and interpreted > just once and *as a single line*. To make it work, you must force a > rescan, using the syntax below and surrounding rescanned variables with > exclamation marks instead of percentage signs. > - There is an extremely active batch file newsgroup: alt.msdos.batch.nt. /Al Quote: > > @echo off > SetLocal EnableDelayedExpansion > > SET OVERWRITE=N > SET /P OVERWRITE="Enter (Y/N) " > SET C_PATH=C:\Windows > > :: BEGIN > IF "%OVERWRITE%"=="Y" ( > ECHO Hey %USERNAME% > ECHO Got IN overwrite > > IF EXIST %C_PATH% ECHO %C_PATH% exist > IF "A"=="A" ECHO Hello!! > ECHO Should not display this message! > ) > > SET COMPILE=N > SET C_OVERWRITE=N > SET /P COMPILE="Enter2 (Y/N) " > > IF "%COMPILE%"=="Y" ( > ECHO Hey2 %USERNAME% > > :: Check if directory is already exist > IF EXIST %C_PATH% ( > ECHO %C_PATH% exist > SET /P C_OVERWRITE="Overwrite %C_PATH% [Y/N] " > ) > > :: Ask for overwrite > IF "%C_OVERWRITE%" == "Y" ECHO C overwrite > ECHO Msg 1 > IF EXIST !C_PATH! ECHO C_PATH exist > ECHO Should not be here! > ) > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| If statement with a message | VB Script | |||
| Help with SQL statement | VB Script | |||
| First 400 Records in SQL Statement | VB Script | |||
| just a statement | Vista General | |||