How to delete files that contain ..

June 3, 2010 at 03:03:44
Specs: Windows XP
Hi,

How can i delete .txt files that contain word "ERROR or "UNABLE" ?

I know that can be done with for /f command, but im not that good at it :(

Any help is welcome.

MUs,


See More: How to delete files that contain ..

Report •

#1
June 3, 2010 at 04:03:51
for /f "delims=" %%a in ('dir /b *.txt') do (
(find "ERROR" %%a || find "UNABLE" %%a)>nul && del %%a
)

Report •

#2
June 3, 2010 at 04:06:36
Assuming the currnt directory is the one holding the text files

@echo off
for %%j in (*.txt) do find "ERROR" "%%j" > nul && del "%%j"
for %%j in (*.txt) do find "UNABLE" "%%j" > nul && del "%%j"


Report •

#3
June 3, 2010 at 04:18:39
Hi,

Thank-you verry much, klint and IVO!

Again i did gain some experience in 'for /f' commands cuz of your reply's!

Kind Regards,

MUs


Report •

Related Solutions

#4
June 3, 2010 at 05:36:48
Ivo's solution uses a simple FOR whereas mine uses FOR /F. I normally would also use a simple FOR. I used FOR /F because I have heard reports that strange things can happen when you are iterating over a number of files, some of which you are deleting at the same time. I have heard anecdotal evidence that using the FOR /F technique appears to work as intended.

By the way, Ivo is right to enclose the variable in quotes. I had forgotten that in my code, it should be "%%a".


Report •

Ask Question