Computing.Net > Forums > Programming > Create Batch to Search Drive and delete file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Create Batch to Search Drive and delete file

Reply to Message Icon

Name: -jay
Date: August 20, 2009 at 10:34:56 Pacific
OS: Windows XP
Subcategory: Batch
Tags: batch, DELETE, batch search
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: ricardo647
Date: August 21, 2009 at 04:56:30 Pacific
Reply:

@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"
)
popd

----------
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


0
Reply to Message Icon

Related Posts

See More


deleting multiple lines i... Batch: Help



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Create Batch to Search Drive and delete file

Batch File search and delete file www.computing.net/answers/programming/batch-file-search-and-delete-file/16386.html

Batch to search all drives and copy newest www.computing.net/answers/programming/batch-to-search-all-drives-and-copy-newest/20316.html

batch to search in .txt and rename www.computing.net/answers/programming/batch-to-search-in-txt-and-rename/17194.html