|
Answer» Hey everyone I am making a sort of multi pupose batch file and one of the abilities it has is gonna be to delete things. I ahve tried the script below but whatever the user inputs to the batch it says it cant file the file specified here is the code:
echo (Note) There is no comfirmation dialog so MAKE SURE you are careful! echo Which file do you want to delete? (Pathname and extension included) SET /p DelFile= del %DelFile% pause cls echo File deleted! Echo. echo 1) Delete another File. echo 2) Main Menu Echo.
set /p ans=%1 if "%ans%"=="1" GOTO:Del2 if "%ans%"=="2" GOTO:Menu
can anyone help?I was able to clean this up a BIT, but you have no labels for your goto statements and you should have a default for your menu (what if a user chooses option 4?)
Code: [Select] @echo off echo (Note) There is no comfirmation dialog so MAKE SURE you are careful! set /p DelFile=Which file do you want to delete? (Pathname and extension included): del %DelFile% cls echo File deleted! Echo. echo 1) Delete another File. echo 2) Main Menu Echo. set /p ans=Enter Option if "%ans%"=="1" GOTO del2 if "%ans%"=="2" GOTO Menu
You should be able to fix the rest of it. Thanks very much for the help and quick reply but it still says that the system cannot find the path specified even tho I am 99% sure ive put it in correctly.Do you know what could be causing this? (btw the code i posted before was only a small section of the batch file)The DEL command is straightforward. It's more likely you're trying to delete a file that doesn't exist. Create a DUMMY file and use your batch file to delete it.
BTW: you'll get a "File Deleted!" message whether the DEL is successful or not. Coding batch FILES is a lot like driving...you have to be defensive.
|