English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm writing a script code for a user friendly deletion batch file.

@echo off

title delete program

echo delete program will now delete files.

pause

del./f /q /s>NUL

del./f /q /s

echo deletion complete

:again

echo Do you want to quit? [y/n]

YN

if errorlevel 49 goto again

if errorlevel 21 goto end

:end

echo Quitting the Master delete program program.

-------------------------------------------------------------------------
the information above I got from this website :

http://www.palmtoppaper.com/ptphtml/25/pt250058.htm

what im trying to do is make a batch file that deletes other files but not itself until the very end, where I want to put an if statement that says if the user answers yes to the Exit? question it deletes the batch file.

but I dont know how to add the exit y/n question or the if statement. and I want to hide the output of the del. command.
to make it look neater!

thats all!! all answers are much appreciated!!

2007-06-27 06:39:11 · 2 answers · asked by Thirsty Attorney 1 in Computers & Internet Programming & Design

2 answers

Here's a snippet that might help. Save this as "test.bat"

It uses the "del" function to ask a yes/no question. You can do what you want in the ":YES" or ":NO" sections. In this case, I've added the code needed to for the batch file to delete itself.

=================
@echo off
type nul>%temp%\~YesOrNo.tmp
echo Would you like to delete this batch file now [y/n]?
del /p %temp%\~YesOrNo.tmp >nul
if not exist %temp%\~YesOrNo.tmp goto Yes
:NO
Echo Selected "No"
del %temp%\~YesOrNo.tmp
goto end
:YES
Echo Selected "Yes"
Start cmd /c del test.bat
:END
==================

To hide the output of the del command you can do what I've done above in the 4th line of code. You use the ">" redirector symbol to redirect the output of "del" to the NULL device. That's done with ">nul". This means that the output normally displayed on the screen will be displayed nowhere.

2007-06-30 13:14:48 · answer #1 · answered by Kevin 7 · 4 0

You need additional utility to chose Y/N as input. Take this one:
http://www.anthonyperlas.com/download/choice.com
--or write your own...

2007-06-27 07:21:09 · answer #2 · answered by alakit013 5 · 0 0

fedest.com, questions and answers