minigun Posted December 12, 2004 Share Posted December 12, 2004 ok so iv been searchin on google for awile now ind im no further to figuring out how to do this so i want my batch file to work like this...press Y or Nif Y then do blablaelsedo blablablahow do i make a batch file do that?? any help guys?? thanx Link to comment Share on other sites More sharing options...
jdoe Posted December 12, 2004 Share Posted December 12, 2004 Search for the SET /P command, I'm sure your gonna find what you want. Link to comment Share on other sites More sharing options...
evilvoice Posted December 12, 2004 Share Posted December 12, 2004 set /p Something="Please press Y or N"If /I %Something%==Y (GOTO This) ELSE GOTO That:Thisblablabla:Thatblablablachange something to whatever you want, also change labels this and that and command blablabla to whatever. Link to comment Share on other sites More sharing options...
my2001 Posted December 12, 2004 Share Posted December 12, 2004 And you could also try this ... the result is quite the same. *hehe*set /p Variable="Please press Y or N"if /I "%Variable%"=="Y" ( echo commands to perform when "y" has been pressed echo you can use more than one command echo just put them on several lines like in batch files) ELSE ( echo commands to perform when "n" has been pressed echo hints from above apply here as well)That way you avoid using GoTos and you can use as many commands as you like. But watch out not to use parentheses within the if-clause! Link to comment Share on other sites More sharing options...
evilvoice Posted December 12, 2004 Share Posted December 12, 2004 it would result in just about the same size of batch file...for my if then clause I only use 1 line, with 2 lines for the gotos...so 3 lines total. in yours, you use 3 lines for your if command...just depends on which of the 2 you will understand...I did try your method for making 2 batch files that run different runonceex and other commands, and it always gave an error...so I switched to the method I use now...I have no idea why it messed up like it did...might have been that I tried doing something youre not supposed to.Good post though...as I said, depends on what you understand about if then statements. Link to comment Share on other sites More sharing options...
Cartoonite Posted December 13, 2004 Share Posted December 13, 2004 If I'm reading these if/then statements correctly, any input other than Y after "Please press Y or N" will execute the else statement. Is there any way to code this so that any input other than Y or N will be ignored?I thought of something like this,:YesNoset /p Variable="Please press Y or N"if /I "%Variable%"<>"Y" and /I "%Variable%"<>"N" goto:Yesnobut this will cause the "Please press Y or N" to be repeated over and over until the correct input is received. I want all input other than Y or N to be silently disregarded. Also, I'm not sure if this is the correct coding for "does not equal." Link to comment Share on other sites More sharing options...
my2001 Posted December 13, 2004 Share Posted December 13, 2004 @evilvoice No problem! It doesn't make any difference for me which "if-method" u wanna use. I personally prefer clean coding and therefore I avoid gotos. They would complicate things quite much here since I use nested IFs. IF ERRORLEVEL 1 ( echo AKTION NICHT AUSGEFUEHRT, Ordner bereits vorhanden. echo 1 - Ordner "%LW_id%\%%d\%Ordner%" schon vorhanden gewesen. ) ELSE ( echo Aktion erfolgreich abgeschlossen, Ordner erstellt. echo 0 - Ordner "%LW_id%\%%d\%Ordner%" erstellt. IF "%Ordner%"=="Anwendungsdaten" ( echo. echo Zusatz: Kopieren der schon vorhandenen Anwendungsdaten an den neuen Platz ... xcopy "%UserProfile%\%Ordner%\*.*" "%LW_id%\%%d\%Ordner%\" /q /h /s /e /i /y /k xcopy "%UserProfile%\Lokale~1\%Ordner%\*.*" "%LW_id%\%%d\%Ordner%\" /q /h /s /e /i /y /k echo. ) )Hhm, as you see it should work out well even with somehow more "complicated" stuff. Don't know what causes the trouble on your PC. Link to comment Share on other sites More sharing options...
my2001 Posted December 13, 2004 Share Posted December 13, 2004 If I'm reading these if/then statements correctly, any input other than Y after "Please press Y or N" will execute the else statement. Is there any way to code this so that any input other than Y or N will be ignored?Try using the "NOT" parameter.IF NOT "%V%"="N" IF NOT "%V%"="Y" commandor ...IF NOT "%V%"="N" IF NOT "%V%"="Y" ( commands)or ...set /p Variable="Please press Y or N"if /I "%Variable%"=="Y" ( echo commands to perform when "y" has been pressed echo you can use more than one command echo just put them on several lines like in batch files) ELSE IF "%Variable%"=="N "( echo commands to perform when "n" has been pressed echo hints from above apply here as well) ELSE ( echo commands to perform when neither "n" nor "y" has been pressed)Just adapt this to your own needs, of course. P.S.: In the first example the second command is just another if command. This way you can nest them as well. In the last one there are just new if else branches - according to one's own need. Link to comment Share on other sites More sharing options...
BritishBulldog Posted December 13, 2004 Share Posted December 13, 2004 this is a lot easier than the above codesdoesnt matter if you use capitals or not both are in therejust add your 'yes' code to where 'echo yes' is and your no code to where 'echo no' is @echo off:startclsset /p userinp=choose a yes/no(Y-N):set userinp=%userinp:~0,1%if "%userinp%"=="Y" goto yesif "%userinp%"=="y" goto yesif "%userinp%"=="N" goto noif "%userinp%"=="n" goto noecho invalid choicegoto start:yesecho YESgoto end:noecho NOgoto end:end pause>nul Link to comment Share on other sites More sharing options...
minigun Posted December 13, 2004 Author Share Posted December 13, 2004 thanx guys i tried all the scripts but could only get BritishBulldogs script to work Link to comment Share on other sites More sharing options...
un4given1 Posted December 14, 2004 Share Posted December 14, 2004 this is a lot easier than the above codesdoesnt matter if you use capitals or not both are in therejust add your 'yes' code to where 'echo yes' is and your no code to where 'echo no' is @echo off:startclsset /p userinp=choose a yes/no(Y-N):set userinp=%userinp:~0,1%if "%userinp%"=="Y" goto yesif "%userinp%"=="y" goto yesif "%userinp%"=="N" goto noif "%userinp%"=="n" goto noecho invalid choicegoto start:yesecho YESgoto end:noecho NOgoto end:end pause>nulDoesn't anyone know you can use a /I switch and cut your "IF" statements in half by not having to use one for "Y" and "y"? Link to comment Share on other sites More sharing options...
gunsmokingman Posted December 14, 2004 Share Posted December 14, 2004 (edited) Here Mine It Has Yes No And A Quit Part For Only One Letter InputECHO OFFCLSCOLOR F2MODE CON: COLS=55 LINES=7TITLE YES NO QUIT:MAINECHO. && ECHO Y FOR YES ® && ECHO N FOR NO ® && ECHO Q FOR QUIT ®SET Choice=SET /P Choice=Type the letter and press Enter: IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%IF /I '%Choice%'=='Y' GOTO YESIF /I '%Choice%'=='N' GOTO NoIF /I '%Choice%'=='Q' GOTO QUITECHO "%Choice%" is not valid. Please try again.GOTO MAIN:YEScls && ECHO. && ECHO Press Key to Return && SET /P = YOU SAID YESGOTO MAIN:NOcls && ECHO. && ECHO Press Key to Return && SET /P = YOU SAID NOGOTO MAIN:QUITcls && ECHO. && SET /P = YOU SAID QUITEXITFor Multiple Letter InputECHO OFFCLSCOLOR F2MODE CON: COLS=55 LINES=7TITLE YES NO QUIT:MAINclsECHO. && ECHO Yes FOR YES ® && ECHO No FOR NO ® && ECHO Quit FOR QUIT ®SET Choice=SET /P Choice=Type the letter and press Enter: IF NOT '%Choice%'=='' SET Choice=%Choice:~0,4%IF /I '%Choice%'=='Yes' GOTO YESIF /I '%Choice%'=='No' GOTO NoIF /I '%Choice%'=='Quit' GOTO QUITECHO "%Choice%" is not valid. Please try again.GOTO MAIN:YEScls && ECHO. && ECHO Press Key to Return && SET /P = YOU SAID YESGOTO MAIN:NOcls && ECHO. && ECHO Press Key to Return && SET /P = YOU SAID NOGOTO MAIN:QUITcls && ECHO. && SET /P = YOU SAID QUITEXITThis Cmd Contains Both Of The Above Code Plus A Menu To Control ItI Edit this now so the menu are straight now Edited December 29, 2005 by gunsmokingman Link to comment Share on other sites More sharing options...
my2001 Posted December 14, 2004 Share Posted December 14, 2004 Well, I think GoTos should DIE 4EVER. Link to comment Share on other sites More sharing options...
BritishBulldog Posted December 15, 2004 Share Posted December 15, 2004 Why should 'GoTo' die my2001? Its one of the 'Beste Befehle in englisch' :-)I GoTo the PubI GoTo the Party I GoTo my mates Link to comment Share on other sites More sharing options...
BritishBulldog Posted December 15, 2004 Share Posted December 15, 2004 Why should 'GoTo' die my2001? Its one of the 'Beste Befehle in englisch' :-)I GoTo the PubI GoTo the Party I GoTo my mates Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now