Creating batch file that would search for a file on hard drive

Asked By 0 points N/A Posted on -
qa-featured

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?

SHARE
Answered By 0 points N/A #82066

Creating batch file that would search for a file on hard drive

qa-featured

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.

Related Questions