Create Batch to Search Drive and delete file

August 20, 2009 at 10:34:56
Specs: Windows XP
Can someone tell me how I create this batch file

When clicked, should search in this directory for 2 specific filenames , if found delete them.

C:\program files\ Java

now the files will be in a subfolder of this depending what version java the person has, the exact path would be...

c:\program files\java\whatever java version\lib\ext\filename.xxxx

See More: Create Batch to Search Drive and delete file

Report •

August 21, 2009 at 04:56:30
@echo off
setlocal enabledelayedexpansion
set target1="test 1.txt"
set target2="test 2.txt"
::targets double quoted
pushd "C:\program files\java"
for /f "tokens=* delims=" %%a in ('dir /b /s *.*') do (
set cfile="%%~na%%~xa"
if /i !cfile!==!target1! del "%%~fa"
if /i !cfile!==!target2! del "%%~fa"

In the above code, target1 and target2 will be deleted in the target folder and in any subfolder bellow it.
I do so intending more flexibility, supposing that the entire name of the path can vary from one to other java version.

but you can make changes and restrain the target folder to c:\program files\java\whatever java version\lib\ext\filename.xxxx

Report •
Related Solutions

Ask Question