This will do what you need, taken you're using windows xp or upper:
Put these lines into a batch file:
findstr /m "failed" *.* > list.txt
for /F "tokens=1 delims= " %%i in (list.txt) do del %%i
Put the batch file in another directory and use a path instead of "*.*", since if you put the batch file in the same directory as the "failed" files, it will get deleted too, since it contains the same string.
Main Topics
Browse All Topics





by: SteveGTRPosted on 2007-09-25 at 10:56:57ID: 19957607
Here's what I came up with. You can pass the directory you want to work on via the command line. If none is specified then the current directory is used. I've disabled the processing so that it echo's out the command. To enable it remove the echo as denoted in the code:
@echo off
setlocal
set workDir=.
set fileMask=*.*
set searchStr=failed
set batchName=%~f0
if not "%~1"=="" set workDir=%~1
if not exist "%workDir%" echo Directory %workDir% does not exist&goto :EOF
pushd "%workDir%"
for /f "tokens=*" %%a in ('dir /b /s "%fileMask%" 2^>NUL') do call :PROCESS "%%a"
popd
goto :EOF
:PROCESS
if "%~f1"=="%batchName%" goto :EOF
findstr /c:"%searchStr%" "%~1" >NUL 2>&1
if /i %errorlevel% EQU 1 goto :EOF
REM ** Remove echo from this command to delete the files
echo del /f /q "%~1"
goto :EOF