Computing.Net > Forums > Programming > Batch file: How to detect

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

Reply to Message Icon

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


Thanks!



Sponsored Link
Ads by Google

Response Number 1
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!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file: How to detect

Batch file: Adding to file names www.computing.net/answers/programming/batch-file-adding-to-file-names/9098.html

Batch file ...how to continue? www.computing.net/answers/programming/batch-file-how-to-continue/17688.html

how to check batch file www.computing.net/answers/programming/how-to-check-batch-file/2856.html