VBScript to clean up a dir

April 10, 2012 at 06:04:54
Specs: Windows 7

I have a DIR that I occasionally need to clean up. It contains a bunch of .txt files and in those files are any number of lines. There is one particular line (Error: Invalid Required Field Subject_ID) that is expected. I am looking for a way to search through all the files and delete any of the ones that only contain the one error and leave the file if it has any other errors besides the expected one.

Here is an example of one file. (This one would need to not be deleted because of the unexpected error on line one)

120402140141_00002.txt Error: Some_other_error
120402140500.txt Error: Invalid Required Field Subject_ID
120402140500_00002.txt Error: Invalid Required Field Subject_ID

Update: I found this on another post.

pushd Your_Folder
for %%j in (*.txt) do type "%%j" | find /I "Error: Invalid Required Field Subject_ID" >nul || echo.%%j >> _pass_fail_results.log

It works, but it does not list any of the files that have other errors. If one string is matched it goes on to the next file. So in this case my _pass_fail_results.log is empty. It does however list a file in the if log if i delete all but the unexpected string.

Thank you.

See More: VBScript to clean up a dir

Report •

April 13, 2012 at 11:09:18
I actually managed to solve this with a batch script.

@echo off
pushd %1
FOR %%a IN (*.txt) DO (
>nul FINDSTR /i /v /c:"Subject_ID" "%%~a"
if errorlevel 1 (
> nul DEL "%%~a"

Report •
Related Solutions

Ask Question