Terminate current command and move to next command in bat file - batch-file

I've created a batch file
#echo off
Mkdir c:\asp
Copy * c:\asp\
Cd/
CD c:\asp
Dir
Pause
If I want to terminate the copy command and move to dir command how can I do so?

Since CTRL + C will terminate overall script and not a single command , I suggest to launch Copy command in a separate CMD window without /WAIT and then use label to go to your desired command ,
#echo off
Mkdir c:\asp
START Copy * c:\asp\
GOTO SABIRLABEL
Cd/
CD c:\asp
:SABIRLABEL
Dir
Pause
You can then use CTRL + C in second window to terminate copy if its long running process.
Also you can make GOTO conditional on some variable value if you don't always wish to skip those two commands.
Hope it helps !!

I think you could use "CHOICE" (available under DOS in Win 8.1)
#echo off
Mkdir c:\asp
HERE goes CHOICE///// etc...
Copy * c:\asp\
Cd/
CD c:\asp
Dir
Pause
Example:
OPEN DOS BOX...
TYPE CHOICE /?
See this...
C:\Windows\system32>choice /?
CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]
Description:
This tool allows users to select one item from a list
of choices and returns the index of the selected choice.
NOTE:
The ERRORLEVEL environment variable is set to the index of the
key that was selected from the set of choices. The first choice
listed returns a value of 1, the second a value of 2, and so on.
If the user presses a key that is not a valid choice, the tool
sounds a warning beep. If tool detects an error condition,
it returns an ERRORLEVEL value of 255. If the user presses
CTRL+BREAK or CTRL+C, the tool returns an ERRORLEVEL value
of 0. When you use ERRORLEVEL parameters in a batch program, list
them in decreasing order.
Examples:
CHOICE /?
CHOICE /C YNC /M "Press Y for Yes, N for No or C for Cancel."
CHOICE /T 10 /C ync /CS /D y
CHOICE /C ab /M "Select a for option 1 and b for option 2."
CHOICE /C ab /N /M "Select a for option 1 and b for option 2."

Related

Batch file unexpected behavior for prompt

I have the following batch file:
echo off
CD \
:Begin
set /p UserInputPath= "What Directory would you like to make?"
if not exist C:\%UserInputPath% (
mkdir %UserInputPath%
) else (
set /p confirm= "Do you want choose another directory?"
echo %confirm%
if "%confirm%"=="y" goto Begin
)
OUTPUT:
C:\>echo off
What Directory would you like to make?ff
Do you want choose another directory?n
y
What Directory would you like to make?
Look at output, Directory ff already Exists, as you see If
I answer n to Do you want choose another directory? Variable
"%confirm% shows as y.
Any ideas?
Windows command processor substitutes all environment variable references using syntax %variable% within a command block starting with ( and ending with matching ) before executing the command which uses the command block.
This means here that %confirm% is replaced twice by nothing on first run of the batch file before the command IF is executed at all. This behavior can be seen on running the batch file without echo off from within a command prompt window, see debugging a batch file.
One solution is using delayed expansion as explained by the help of command SET output on running in a command prompt window set /? on an IF and a FOR example.
But much better is avoiding command blocks where not really necessary.
In this case usage of command CHOICE for the yes/no prompt is also better than set /P.
#echo off
cd \
goto Begin
:PromptUser
%SystemRoot%\System32\choice.exe /C YN /N /M "Do you want to choose another directory (Y/N)? "
if errorlevel 2 goto :EOF
:Begin
set "UserInputPath="
set /P "UserInputPath=What Directory would you like to make? "
rem Has the user not input any string?
if not defined UserInputPath goto Begin
rem Remove all double quotes from user path.
set "UserInputPath=%UserInputPath:"=%"
rem Is there no string left anymore?
if not defined UserInputPath goto Begin
rem Does the directory already exist?
if exist "%UserInputPath%" goto PromptUser
rem Create the directory and verify if that was really successful.
rem Otherwise the entered string was invalid for a folder path or
rem the user does not have the necessary permissions to create it.
rem An error message is output by command MKDIR on an error.
mkdir "%UserInputPath%"
if errorlevel 1 goto Begin
rem Other commands executed after creation of the directory.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
cd /?
choice /?
echo /?
goto /?
if /?
mkdir /?
rem /?
set /?
See also:
Where does GOTO :EOF return to?
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?

How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?

If I have the following example code:
#echo off
:menu
cls
echo 1. win
echo 2. lose
set /p menu=
goto %menu%
pause>nul
:win
cls
echo yay lolz
pause>nul
:lose
cls
echo really?
pause>nul
How do I stop the batch from quitting if I type "test" instead of a valid response?
1. Documentations for the Windows commands
I suggest bookmarking in your browser:
Microsoft's command-line reference
An A-Z Index of the Windows CMD command line (SS64)
There can be get help for each Windows command by running in a command prompt window the command with /? as parameter, for example if /?, set /?, ... The execution of help results in an output of an incomplete list of Windows commands with a brief description.
2. Usage of SET /P for user prompts
It is advisable not using set /p if the user should choose from one of several offered options. There are multiple facts which must be taken into account on prompting a user for entering a string and assigning it to an environment variable:
The environment variable MyVar is not modified on usage of set /P "MyVar=Your choice: " if the user presses intentionally or by mistake just RETURN or ENTER. This means if the environment variable MyVar is not defined already before the user prompt, it is still not defined after the user prompt finished with just hitting key RETURN. And if MyVar is defined already before the user prompt, it keeps its value unmodified in case of the user presses just RETURN or ENTER. The command SET exits with error value 1 on user did not enter a string at all as documented by What are the ERRORLEVEL values set by internal cmd.exe commands?
The user has the freedom to type any string on being prompted with set /P. The batch file author has no control on what the user really enters. So the batch file author must take into account that the user enters by mistake or intentionally a string which could result in an exit of batch file execution because of a syntax error, or it does something completely different as it is defined for.
A simple example:
#echo on
:MainMenu
#set /P "menu=Your choice: "
if %menu% == 1 goto Label1
if %menu% == 2 goto Label2
goto MainMenu
:Label1
#echo Option 1 was chosen, fine.
exit /B
:Label2
#echo Option 2 was chosen, okay.
This batch file with echo on instead of echo off at top is started from within a command prompt window for debugging purposes.
Just RETURN is pressed on user prompt on first run. Windows command interpreter exits the batch file processing because first IF condition is preprocessed before execution of IF command to:
if == 1 goto Label1
There is obviously missing the first argument. cmd.exe encounters this syntax error and exits batch processing with an appropriate error message. The reason is the missing definition of environment variable menu which is not defined before user prompt and is still not defined after user prompt.
The string 2 is entered on second run of the batch file from within command prompt window and the batch file works as expected.
On third run of the batch file from within same command prompt window again just RETURN is pressed on user prompt. The batch file outputs again the second message. Why? The environment variable menu is still defined from second batch file execution with that string and the variable was not modified on pressing RETURN.
Okay, let us modify the example batch file to:
#echo on
:MainMenu
#set "menu=2"
#set /P "menu=Your choice: "
if "%menu%" == "1" goto Label1
if "%menu%" == "2" goto Label2
goto MainMenu
:Label1
#echo Option 1 was chosen, fine.
exit /B
:Label2
#echo Option 2 was chosen, okay.
This is already better as now environment variable menu is always predefined with value 2. So if the user enters nothing, a jump to Label2 is done. Also the value of previous run of variable menu has no effect anymore on execution of the batch file.
Another solution would be making use of exit code 1 on user not entering a string at all and define only in this case the environment variable with a default value by using:
#set /P "menu=Your choice: " || set "menu=2"
Single line with multiple commands using Windows batch file describes the conditional execution operator || to run the second command set "menu=2" only if the first executed prompt command set /P "menu=Your choice: " exits with an exit code not equal 0 as done when the user does not enter anything at all.
Thanks aschipfl for this contribution.
But is that really secure and fail safe now?
No, it isn't. The user still can enter by mistake a wrong string.
For example the user enters by mistake " instead of 2 which is easy on German keyboards as CapsLock+2 or Shift+2 results in entering ". The first IF command line after preprocessing is now:
if """ == "1" goto Label1
And this is again an invalid command line resulting in an exit of batch file processing because of a syntax error.
Let us assume a user enters on prompt the string:
" == "" call dir "%USERPROFILE%\Desktop" & rem
Note: There is a space at end.
The first IF condition is preprocessed by Windows command interpreter to:
if "" == "" call dir "%USERPROFILE%\Desktop" & rem " == "1" goto Label1
It can be seen that the batch file executes now a command not written in the batch file at all on both IF conditions.
How to get a user prompt fail safe and secure?
A user prompt can be made fail safe and secure by using delayed variable expansion at least for the code evaluating the string input by the user.
#echo on
:MainMenu
#setlocal EnableDelayedExpansion
#set "Label=MainMenu"
#set /P "menu=Your choice: " || set "menu=2"
if "!menu!" == "1" set "Label=Label1"
if "!menu!" == "2" set "Label=Label2"
endlocal & goto %Label%
:Label1
#echo Option 1 was chosen, fine.
exit /B
:Label2
#echo Option 2 was chosen, okay.
Now the user input string does not modify anymore the command lines executed by Windows command processor. So an exit of batch file processing because of a syntax error caused by user input is not possible anymore (fail safe). Furthermore, the batch file never executes commands not written in batch file (secure).
3. Usage of CHOICE for a choice prompt
There is a better command than set /P for a simple choice menu – CHOICE.
#echo off
:MainMenu
cls
echo/
echo 1 ... Option 1
echo 2 ... Option 2
echo E ... Exit
echo/
%SystemRoot%\System32\choice.exe /C 12E /N /M "Your choice: "
if errorlevel 3 exit /B
if errorlevel 2 goto Label2
if not errorlevel 1 goto MainMenu
#echo Option 1 was chosen, fine.
exit /B
:Label2
#echo Option 2 was chosen, okay.
The user has no freedom anymore to enter something not defined by batch file author. The batch file continues immediately after the user has pressed either 1, 2, E or Shift+E. Everything else is ignored by choice with exception of Ctrl+C.
The dynamic variable ERRORLEVEL has with three options nearly always a value in range 1 to 3 after choice terminated with returning 1 to 3 as exit code to calling cmd.exe. The exception is the rare use case that the user of a batch file pressed Ctrl+C on prompt and answers the next prompt Terminate batch job (Y/N)? of cmd.exe with N. In this case the dynamic variable ERRORLEVEL has the value 0 which is the reason for if not errorlevel 1 goto MainMenu to handle also this very special use case.
Note: if errorlevel X means IF GREATER OR EQUAL X. So it is always necessary to start with highest possible exit code of command choice.
As the exit code assigned to ERRORLEVEL is well known, it is possible on larger menus to optimize the code further by using appropriate labels:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "ERRORLEVEL="
:MainMenu
cls
echo/
echo 1 ... Option 1
echo 2 ... Option 2
echo E ... Exit
echo/
%SystemRoot%\System32\choice.exe /C 12E /N /M "Your choice: "
goto Label%ERRORLEVEL%
:Label0
rem The user pressed Ctrl+C and on next prompt N and
rem so made no choice. Prompt the user once again.
goto MainMenu
:Label1
#echo Option 1 was chosen, fine.
exit /B
:Label2
#echo Option 2 was chosen, okay.
exit /B
:Label3
The usage of command CHOICE can make choice menus very simple to code.
The third command line makes sure that there is not defined by chance an environment variable with name ERRORLEVEL which would otherwise prevent accessing the current value of dynamic variable ERRORLEVEL using with the exit code of command CHOICE using the syntax %ERRORLEVEL%.
Note: The usage of goto Label%ERRORLEVEL% is only possible with the choice menu command lines not being inside a command block starting with ( and ending with a matching ).
See also: How can I make an "are you sure" prompt in a Windows batch file?
Hint 1: There is a beep sound output by CHOICE if the user presses a not acceptable key. It is not possible to suppress that beep as there is no option offered by CHOICE to avoid output of the beep sound.
Hint 2: See also my answer on Where does GOTO :EOF return to? explaining also exit /B.

Bat User Selection

This is a simple question that I haven't been able to find an answer to. I am running a script that requires user input/selection. Here is the problematic area:
echo W -- WATCH_SCALE
echo E -- EARRING_SCALE
echo R -- RING_SCALE
echo B -- BOX
set /P rnFunc="choose a script: "
for %%I in (W E R B x) do if #%rnFunc%==#%%I goto assign%%I
The script works if user inputs the correct letter, however if user inputs an undefined letter such as 'T' the script continues on to the first option instead of breaking. I would like this to only work if the user inputs a W, E, R or B. What would my best option be?
Thanks so much.
You may want to take a look at the CHOICE command instead.
CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]
Description:
This tool allows users to select one item from a list
of choices and returns the index of the selected choice.
Parameter List: /C choices Specifies the list of choices to be created.
Default list is "YN".
/N Hides the list of choices in the prompt.
The message before the prompt is displayed
and the choices are still enabled.
/CS Enables case-sensitive choices to be selected.
By default, the utility is case-insensitive.
/T timeout The number of seconds to pause before a default
choice is made. Acceptable values are from 0 to
9999. If 0 is specified, there will be no pause
and the default choice is selected.
/D choice Specifies the default choice after nnnn seconds.
Character must be in the set of choices specified
by /C option and must also specify nnnn with /T.
/M text Specifies the message to be displayed before
the prompt. If not specified, the utility
displays only a prompt.
/? Displays this help message.
NOTE: The ERRORLEVEL environment variable is set to the index of the
key that was selected from the set of choices. The first choice listed
returns a value of 1, the second a value of 2, and so on. If the user
presses a key that is not a valid choice, the tool sounds a warning
beep. If tool detects an error condition, it returns an ERRORLEVEL
value of 255. If the user presses CTRL+BREAK or CTRL+C, the tool
returns an ERRORLEVEL value of 0. When you use ERRORLEVEL parameters
in a batch program, list them in decreasing order.
Examples:
CHOICE /?
CHOICE /C YNC /M "Press Y for Yes, N for No or C for Cancel."
CHOICE /T 10 /C ync /CS /D y
CHOICE /C ab /M "Select a for option 1 and b for option 2."
CHOICE /C ab /N /M "Select a for option 1 and b for option 2."
Adding a goto end right after the for statement. Then make a label called end after all the other labels should solve your problem. Basically the first encountered label is being executed since it failed the for statement.

Call batch within batch?

How do I call multiple batch files within a single batch? When I try it always goes to the same one or none at all and closes window.
#echo off
:MENU
title MENU0
Echo 1 - Select Menu 1
Echo 2 - Select Menu 2
Echo 0 - Exit
Echo.
SET /P choice=Type the number or letter of task you want, then press ENTER:
IF %choice%==1 GOTO 1
IF %choice%==2 GOTO 2
IF %choice%==0 EXIT
:1
call %userprofile%\desktop\\Menu1.bat
:2
call %userprofile%\desktop\Menu2.bat
There are several issues with provided batch code in question.
The first one is that after processing of the batch file called with command CALL finished, the processing of current batch file continues with the next command respectively line, except the called batch file contains itself the command EXIT without parameter /B as in this case the command processor terminates itself independent on calling hierarchy.
For details about CALL behavior see answers on:
How to call a batch file in the parent folder of current batch file?
In a Windows batch file, can you chain-execute something that is not another batch file?
The second issue is that folder path assigned to environment variable USERPROFILE could contain 1 or more spaces (default on Windows 2000/XP, possible on later Windows versions depending on user name). Therefore always enclose a string referencing USERPROFILE or USERNAME in double quotes.
The third and most difficult to handle issue is that the user of a batch file on prompt with set /P has the freedom to enter anything and not just what the writer of the batch file suggests.
For example
SET /P choice=Type the number or letter of task you want, then press ENTER:
IF %choice%==1 GOTO 1
results in an exit of batch processing caused by a syntax error if the batch user hits just RETURN or ENTER without entering anything at all and the environment variable choice is not already defined with a useful string because in this case the next line to process by command processor is:
IF ==1 GOTO 1
It is good practice to define the environment variable with a default value before set /P as this value is kept when the batch user just hits RETURN or ENTER.
A batch user has also the freedom on using set /P to enter anything including syntax critical characters like " or < or | or > and others by mistake or intentionally (for breaking batch processing by a syntax error).
Therefore it is in general better for menus in batch files to use the command choice (Microsoft article) because then the batch user can enter only what the writer of the batch file offers. But CHOICE is available only by default for Windows Server 2003 and later Windows. And there are different versions of choice (SS64 article with additional information) with a different set of options. So it depends on which Windows version(s) the batch file is designed for if CHOICE can be used at all.
It is also not good to name an environment variable or a label like a command although possible. Therefore choice is not a good name for an environment variable.
Here is a commented batch file with a code which avoids all those issues.
#echo off
:MainMenu
setlocal EnableDelayedExpansion
title MENU0
cls
echo 1 - Select Menu 1
echo 2 - Select Menu 2
echo 0 - Exit
echo.
rem Define 0 as default value in case of user just hits RETURN or ENTER.
set "UsersChoice=0"
set /P "UsersChoice=Type the number or letter of task you want, then press ENTER: "
rem Has the user really entered just one of the offered characters?
rem There must be nothing to process if the user has entered just 0
rem or 1 or 2. Otherwise the user's choice was either by mistake or
rem intentionally entered wrong. The string entered by the user is
rem referenced with delayed expansion to avoid an exit of batch
rem processing in case of user entered a syntax critical character.
for /F "tokens=1 delims=012" %%I in ("!UsersChoice!") do (
endlocal
goto MainMenu
)
rem Now it is safe to reference the variable value without usage of delayed
rem expansion as a syntax error caused by user input can't occur anymore.
rem The entered string does not contain any not expected character. But
rem it is possible that for example 11 was entered by mistake instead
rem of just 1. The entered string should have a length of 1 character.
if not "%UsersChoice:~1,1%" == "" (
endlocal
goto MainMenu
)
rem Exit this batch processing on user entered 0. Previous environment is
rem automatically restored by command processor by an implicit endlocal.
if "%UsersChoice%" == "0" exit /B
rem Restore previous environment as the called batch files are most
rem likely written for using standard command environment with delayed
rem expansion not enabled (exclamation mark interpreted different).
rem The current value of local environment variable must be passed
rem to previous environment for usage on GOTO command.
endlocal & goto Menu%UsersChoice%
:Menu1
call "%USERPROFILE%\Desktop\Menu1.bat"
goto MainMenu
:Menu2
call "%USERPROFILE%\Desktop\Menu2.bat"
goto MainMenu
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
cls /?
echo /?
endlocal /?
exit /?
for /?
goto /?
rem /?
set /?
setlocal /?
title /?
For meaning of & in line endlocal & goto Menu%UsersChoice% see answer on Single line with multiple commands using Windows batch file.
I tried your code and what I found was that when the input was 1 both :1 and :2 are executed but when the input is 2 only :2 is executed. To fix this you need to specify the end of :1 using Exit or another goto.
You might see that none the batches are being executed IF you do not put a pause in the end of your script. They would be executed but the result might just flash out of the screen.
Also I do not understand why have you used \\Menu1.batand not \Menu1.bat in
:1
call %userprofile%\desktop\\Menu1.bat
The final working code for me-
#echo off
:MENU
title MENU0
Echo 1 - Select Menu 1
Echo 2 - Select Menu 2
Echo 0 - Exit
Echo.
SET /P choice=Type the number or letter of task you want, then press ENTER:
IF %choice%==1 GOTO 1
IF %choice%==2 GOTO 2
IF %choice%==0 EXIT
:1
call yourpathhere\Menu1.bat
pause
GOTO cont
:2
call whatsoever\Menu2.bat
pause
GOTO cont
:cont
exit
That should fix your problem.
Hope I helped.
I may not be a pro, but I could help you!
I always add extra code on my games in order to avoid bugs, like this:
set /p letter=
if %letter% == 1 goto nocheck1
if %letter% == 2 goto nocheck2
if %letter% == 3 exit
:nocheck1
if %letter% == 1 goto saves
:nocheck2
if %letter% == 2 goto howtoplay
Maybe it could work on your problem!
I might have the code to do it:
#echo off
cls
:menu
cls
echo 1. Open Batch 1
echo 2. Open Batch 2
set /p test=Enter number here ----->
if %test% == 1 goto check1
if %test% == 2 goto check2
Edit the "Batch file name" text with your location of your batch file.
:check1
if %test% == 1 start C:\Users\%username%\Desktop\(batch file name).bat
:check2
if %test% == 2 start C:\Users\%username%\Desktop\(batch file name).bat
If there's still any errors with my code, let me know.
Hope this helps your problem!
Use cd to go to the location of batch file. For example:
rem myscript
echo calling batch file
cd demo\desktop\script
execute.bat
echo done
After the execution of that batch, control will return to the next line of your script.
Use "Start" instead of "Call" like so,
#echo off
:MENU
title MENU0
Echo 1 - Select Menu 1
Echo 2 - Select Menu 2
Echo 0 - Exit
Echo.
SET /P choice=Type the number or letter of task you want, then press ENTER:
IF %choice%==1 GOTO 1
IF %choice%==2 GOTO 2
IF %choice%==0 EXIT
:1
start %userprofile%\desktop\\Menu1.bat
:2
start %userprofile%\desktop\Menu2.bat
Try This:
#echo off
:MENU
title MENU0
Echo 1 - Select Menu 1
Echo 2 - Select Menu 2
Echo 0 - Exit
Echo.
SET /P choice=Type the number or letter of task you want, then press
Enter:
IF %choice%==1 GOTO 1
IF %choice%==2 GOTO 2
IF %choice%==0 EXIT
:1
cd users
cd %userprofile%
cd desktop
:: call Menu1.bat or use: start Menu1.bat
:: exit
:2
cd users
cd %userprofile%
cd desktop
:: call Menu2.bat or use: start Menu2.bat
:: exit
start "" C:\location\of\file\file.bat
This opens a new window, and as long as you have more commands to follow, the previous file that is calling the new one will still run along with this one.

Batch file with choosing Y/N

Please help, I'm a beginner and I need to create batch-file to delete log-files. But before delete I need to ask user to delete the last log-file or all log-files.
I tried to implement it like:
set /P PARAM_VALUE=Remove only the last log file?(Y/N)?
if /I "%PARAM_VALUE%"=="y" goto DeleteLast
if /I "%PARAM_VALUE%"=="n" goto DeleteAll
But in this case I can enter any values, I need to avoid an others character except Y,y,N,n.
Thx.
One of solutionі in this case is using the CHOICE command.
This tool allows users to select one item from a list of choices and returns the index of the selected choice.
Syntax: CHOICE [ /C choices ] [ /N ] [ /CS ] [ /T timeout /D choice ] [ /M text ]
Parameter List:
/C choices Specifies the list of choices to be created. Default list for English versions is YN
/N Hides the list of choices in the prompt. The message before the prompt is displayed and the choices are still enabled.
/CS Enables case-sensitive choices to be selected. By default, the utility is case-insensitive. Note: DOS and NT Resource Kit versions use /S instead
/T timeout The number of seconds to pause before a default choice
is made. Acceptable values are from 0 to 9999.
If 0 is specified, there will be no pause and the default choice is selected.
Note: DOS and NT Resource Kit versions use /T:default,timeout instead.
/D default Specifies the default choice after timeout seconds.
Character must be in the set of choices specified by /C option and must also specify timeout with /T.
Note: DOS and NT Resource Kit versions use /T:default,timeout instead.
/M text Specifies the message to be displayed before the prompt.
If not specified, the utility displays only a prompt.
For your problem try to use something like:
choice /C:YN /M:"Remove only the last log file? [YN]"
IF ERRORLEVEL ==1 GOTO DeleteLast
IF ERRORLEVEL ==2 GOTO DeleteAll
GOTO next
:DeleteAll
rem delete all
:DeleteLast
rem delete last
:next
rem continue work with Batch file
You can just catch all other inputs like this:
:CONFIRM
if /i "%PARAMVALUE%"=="y" goto DeleteLast
if /i "%PARAMVALUE%"=="n" goto DeleteAll
echo Please enter only Y/y or N/n!
ping localhost -n 2 >nul
goto CONFIRM
I used this too for my own scripts and it works wonderfully and is super easy!
The delete command already offers a prompt N/y
EDIT
del /p
type del /? in console for more information
UPDATE
you can test with this example:
#echo off
SETLOCAL
Echo:
Echo /!\ Creating a bunch of empty files /!\
echo Press any key to continue or CTRL-C to exit...
Pause>nul
for /L %%A in (1,1,4) do (copy /y NUL _temp_file_%%A.ext)
Echo:
Echo /!\ Deleting a bunch of empty files with command prompt /!\
echo Press any key to continue or CTRL-C to exit...
Pause>nul
del /p "_temp_file_?.ext"
Echo:
Pause>nul|(echo Press any key to exit...)

Resources