windows 7 to list last generated file if there is any error

November 10, 2014 at 23:06:16
Specs: Windows 7
Hi All,
Would like to use windows batch script to list last log file generated from a directory if there is error in the contents.

OS Use : Windows 7

Thanks.

message edited by ckwan


See More: windows 7 to list last generated file if there is any error

Report •


#1
November 11, 2014 at 00:59:49
::
::====== script starts here ===============
:: finds latest log w error
:: lasterr.bat 2014-11-11 15:47:30.55
@echo off & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=* delims= " %%a in ('dir/b/o-d *.log') do (
find /i "error" < %%a > nul
if not errorlevel 1 (
echo %%a
goto :donemain
)
)
:donemain
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
November 11, 2014 at 17:42:12
Thanks Mechanix2Go, but this seems does not work in my environment, I had tested the script it only return me the last filename, is it possible to once found the error found in the log, need to set errorlevel and return it to calling program.

Report •

#3
November 11, 2014 at 19:36:49
What do you want errorlevel set TO?

=====================
M2 Golden-Triangle


Report •

Related Solutions


Ask Question