Asked By
s.susan74
0 points
N/A
Posted on - 01/25/2012
I need help in creating a batch file that would search for a file on my hard drive and would permanently delete the file when it is found.
Would it be possible to display a message such as “file successfully found and deleted” if it has succeeded in the task?
Creating batch file that would search for a file on hard drive
Here is the solution for the problem.
1) Open a notepad file.
2) Add the below script into a notepad file.
@ECHO OFF
cd
set var=dir %1 /s
IF ERRORLEVEL 0 GOTO CANDELETE
GOTO END
:CANDELETE
DEL %var%
ECHO "File Successfully found and deleted"
ECHO &PAUSE
:END
ECHO &PAUSE
3) Save the notepad file as batch.txt to destktop.
4) Rename the batch.txt text file to Deletefile.bat file.
5) Open a command line prompt using the Start -> Run -> and Type cmd
6) Go to the Desktop folder. cd desktop
7) Enter the command – Deletefile <filename to search and delete>
6) This will find the files and will remove the files if found permanantly.