@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"
:: Need to put YOUR setting of %TODAY% in here - I'm using constants for testing
SET today=20140109
FOR %%a IN ("%sourcedir%"\beenprocessed*.txt) DO IF /i NOT "%%a"=="%sourcedir%\beenprocessed%today%.txt" DEL "%%a"
IF NOT EXIST "%sourcedir%\*%today%.log" GOTO :eof
ECHO dummy>>"%sourcedir%\beenprocessed%today%.txt"
findstr /i /c:"The_database_has_been_locked." "%sourcedir%\*%today%.log" >"%sourcedir%\beINGprocessednow.txt"
FINDSTR /i /v /b /e /g:"%sourcedir%\beenprocessed%today%.txt" "%sourcedir%\beINGprocessednow.txt" >>"%destdir%\Error.txt"
type "%sourcedir%\beINGprocessednow.txt" >> "%sourcedir%\beenprocessed%today%.txt"
GOTO :EOF
You'd need to insert your setting of %today%
- I just used a constant. Also, I've set source and destination directories as variables. Just a matter of making changes.
I'm not fussed whether the ...beenprocessed...
and ...beingprocessednow...
files are in %sourcedir%
, %destdir%
, %temp%
or %someotherdir%
. Up to the programmer to choose.
The principle is this:
append a dummy string into beenprocessed...
. This either creates a file or appends to it, a string that simply won't be of interest (it fails the '...database_has_been...` filter).
Find all of the target records in the logs and place them in a file beingprocessednow
.
Find all of the lines in beingprocessednow
that don't appear in beenprocessed
- ie. the new lines, and append them to the error.txt
file.
Append the entire contents of beingprocessednow
to beenprocessed
which includes the new data
At startup, the beenprocessed
files for any day other than today are deleted.
dummy
needs to be added to the "words to exclude" because findstr ../g
requires at least one string in the file. dummy
can't be a valid word which occupies exectly one line (/b /e
) because all lines of interest contain the target string.