tags:

views:

143

answers:

3

I have a batch file that automates copying a bunch of files from one place to the other and back for me. Only thing is as much as it helps me I keep accidentally selecting that command off my command buffer and mass overwriting uncommited changes.

What code would I need for my .bat file to make it say "are you sure", and make me type "y" before it ran the rest of the file? If anything but "y" is typed it should exit execution on that line.

Edit Nov 27 Ok I marked this unanswered again because I still can't figure it out. When I call "exit;" it closes cmd.exe which is not what I want. All this because Windows implemented command buffer wrong [differently than what I am used to at least]

+3  A: 

try the CHOICE command

Steven A. Lowe
<show off>Though this is relatively new. It was added in MS-DOS 6 in 1993 or 1994, so it may not work with all implementations</show off>
Nathan Fellman
+6  A: 

choice is not available everywhere. with newer windows, the set command has the /p option you can get user input

SET /P variable=[promptString]

see set /? for more info

+1 choice dont even work in windows 2000
S.Mark
+2  A: 

You want something like:

@echo off
setlocal
:PROMPT
SET /P AREYOUSURE=Are you sure (Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO END

echo ... rest of file ...


:END
endlocal
Joe
Thanks, can't stand windows.
Josh Ribakoff