Computing.Net > Forums > Programming > search and delete batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

search and delete batch file

Reply to Message Icon

Name: moviesnmore
Date: April 18, 2008 at 10:56:31 Pacific
OS: xp, 2003
CPU/Ram: n/a
Product: n/a
Comment:

I found this code and tried to modify it for my purposes.

I wanted to find the word "cookie" in some text based files and then delete the file if found. If the word "cookie" is on its own line, the file is deleted. But if the word is in the middle of a string, it is not deleted. Any thoughts on how to fix this?

----------------

@echo off
setLocal EnableDelayedExpansion

pushd d:\Temp

for /f "tokens=* delims=* " %%e in ('dir/b/a-d *.pkg') do (
for /f "tokens=* delims=* " %%a in (%%e) do (
echo %%a | find "cookie" > nul
if not errorlevel 1 echo del %%e
)
)



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 18, 2008 at 11:41:23 Pacific
Reply:

What if a file has a line with cookie on a line by itself and the same file has cookie within a string? What then?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: klint
Date: April 19, 2008 at 15:05:56 Pacific
Reply:

@echo off
for /f "delims=" %%f in ('findstr /m /x /c:"cookie" d:\Temp\*.pkg') do (
echo del %%f
)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: search and delete batch file

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

self deleting batch file www.computing.net/answers/programming/self-deleting-batch-file/16219.html

Batch File deleting files by date? www.computing.net/answers/programming/batch-file-deleting-files-by-date/13717.html