Rob van der Woude's Scripting Pages

Solutions found in alt.msdos.batch

and alt.msdos.batch.nt

Obtaining Y/N user input

Clay Calvert posted this interesting solution to obtain Y/N user input in most DOS versions:

Here's an old trick that works in most MS operating systems.
A writeable %temp% directory is required.

@echo off
type nul>%temp%\~YesOrNo.tmp
echo Would you like to do this now [y/n]?
del /p %temp%\~YesOrNo.tmp>nul
if not exist %temp%\~YesOrNo.tmp goto Yes
Echo Selected "No"
del %temp%\~YesOrNo.tmp
goto end
:Yes
Echo Selected "Yes"
:end

Clay Calvert

The trick is DEL's /P switch (prompt for confirmation) that was introduced in either MS-DOS 5 or 6, I'm not quite sure which one.
If this batch file is to be used in Windows 2000 or XP, make sure you enclose the temporary file name in double quotes if it contains any spaces (which it does by default).

 

More info on user input on my User Input page.


page last modified: 2011-03-04; loaded in 0.0014 seconds