Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Batch file: How to detect
Name: knhcmp Date: March 11, 2008 at 15:55:06 Pacific OS: XP Pro CPU/Ram: 2 GB Product: Dell
Comment:
(repost with propper text for subject)
My batch code (below) prompts the users for a "Y/y" or "N/n" input.
How can I detect when the <return> key was pressed instead (this is so I can treat the <return> as a "Y/y")?
:CONFIRM echo Y/y or N/n set/p "cho=>" REM if %cho%==%CR% goto LOCK <- doesn't work if %cho%==Y goto LOCK if %cho%==y goto LOCK if %cho%==n goto END if %cho%==N goto END REM echo Invalid choice goto CONFIRM :LOCK ... :END
Name: Mechanix2Go Date: March 12, 2008 at 02:17:54 Pacific
Reply:
@echo off setLocal EnableDelayedExpansion
set /p cho= if !cho!'==' (goto :eof ) else ( goto :!cho! )
:y echo yes goto :eof
:n echo no
===================================== If at first you don't succeed, you're about average.
M2
0
Response Number 2
Name: knhcmp Date: March 12, 2008 at 09:28:02 Pacific
Reply:
Mechanix2Go: At first, I had problem understanding your code (it was rather cryptic to a newbie like me). But after playing around with it a bit; W h o a... I understood what you were doing! Your way and Klint's are 2 widely different ways to skin this cat. If anything, this show how neat & powerful batch script can be. Thanks!
Summary: Hi, I’m stuck on part of a batch file I’m working on. What I’m trying to do is copy all files with the extension JPE in a directory to another directory, adding “ (E-mail Size)” to the file name and m...
Summary: Sorry I didn't know where to post this. Here's the deal. I'm creating a bat file to load some programs and it was going ok. First line of the script I want it to open a TEXT file that has informatio...
Summary: I am just begining to learn about batch files and am starting out very easy. Is there any way to run a check on a batch file to show where you went wrong in the programing. I am working on a batch fil...