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.
When I call "exit;" it closes cmd.exe which is not what I want.
Pipe the echo [y|n] to the commands in Windows PowerShell or CMD that ask “Yes/No” questions, to answer them automatically.
The del command displays the following prompt: Are you sure (Y/N)? To delete all of the files in the current directory, press Y and then press ENTER. To cancel the deletion, press N and then press ENTER.
To have a batch file stop and prompt for input, you would want to look into using set /p , which will prompt for input and then assign that input to a variable. e.g.: set /P name="What Is Your Name? " echo Hello %name%!
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With