1.

Solve : Writing a batch file?

Answer»

Hiya
Can any one tell me how to WRITE a batch a file that will delete a FOLDER specifed by the user of the batch file, when they RUN it.
Eg to delete the folder "user" that is in c:\documentsandsettings\user
all the user of file would have todo is when prompted type in the file name they wanted to delete, "user"
Thanx any help would be much appreciated
Beginner programerFrom long ago and not so long ago DOS experience, when the batch file is called, have the user specify the full path of the file to be deleted
BATDelete C:\Documentsandsettings\user

And the .BAT file would contain:
ECHO OFF
DEL %1

But that then raises some questions.
What if the file doesn't exist?
What if the user of the .BAT file specifies the wrong file? Shouldn't we give the user the responsibility to verify and affirm the file to be deleted? The DOS delete in .BAT files does not place the file in trash - the file just dissapears!

So, using the same batch file call, lets improve what happens:
ECHO OFF
IF EXIST %1% goto XX1
ECHO.
ECHO File %1 does not exist
echo.
GOTO XXX
:XX1
Echo.
echo File %1 Is this the file you want to delete
ECHO Press any key to delete this file.
ECHO Press CTRL-C to terminate without deleting.
PAUSE
DEL %1
:XXX

To learn more about DOS and BATCH files (which work in WindowsXP, do a GOOGLE SEARCH for "batch file parameters" without the quotes as an EXACT search in Google.com/advanced_search

Chris Cthanx for the help but also need to know how i can make it remeber what is firist type at the prompt "what is your username?" then transfer it to the part of script, where it REMOVES the dir the line is "set cmd= rmdir"
can anybody help

This is script so far
:SET
echo.
set SET=
set /p SET=What is your username?
goto remove
:end

:remove
cd c:\docume~1
set cmd= rmdir
echo.
set /p cmd= Please press return to delete file.
%cmd%
goto pause

:pause
pause
:end



ThanxWith Win9x, you had a command DELTREE that would unconditionally wipe out a target directory tree. Your batch file could be as simple as

xd user

and the batch file would be XD.BAT:

deltree "c:\my documents\%1"
md "c:\my documents\%1"


With XP CLI emulation, the DELTREE command was stupidly omitted, so the user is stuck with only being able to delete the file content of a single directory:

del "c:\documents and settings\%1\my documents\%1\*.*" /y

The subdirectories of this remain intact, but the user's root content is deleted.



Discussion

No Comment Found