Batch file to zip Apache Tomcat for windows file names that do not equal to today -
we have number of apache tomcat windows logs - example..
server.log.2014-02-04-10 server.log.2014-02-04-11 server.log.2014-02-04-12 server.log.2014-02-05-13 server.log.2014-02-05-14 server.log.2014-02-05-15
these defined file extension of .yyyy-mm-dd-hh , default apache has them date: .yyyy-mm-dd however, have define hh breakover because of system usage , other reasons. trying simple.. if file extension not equal today, archive (zip) up..
here have , no matter shows: 2014-02-05 though script showing .2014-02-04.
here script , not sure if need setlocal enabledelayexpansion..
rem http://www.dostips.com/dttipsstringmanipulation.php#snippets.replace setlocal enabledelayedexpansion /f "skip=1" %%x in ('wmic os localdatetime') if not defined mydate set mydate=%%x set today=!mydate:~0,4!-!mydate:~4,2!-!mydate:~6,2! rem today=%mydate:~0,8% %%i in (d:\11\*.*) ( set filetime=%%~xi rem set dt=!filetime:~0,11! rem if not "!fldt!" == ".!today!" ( rem echo %%~ni%%~xi rem ) ) pause
thanks
this filters filenames date string in name and
echo filenames not have todays date in them.
@echo off rem http://www.dostips.com/dttipsstringmanipulation.php#snippets.replace setlocal enabledelayedexpansion /f %%x in ('wmic os localdatetime ^|find "." ') set "mydate=%%x" set "today=!mydate:~0,4!-!mydate:~4,2!-!mydate:~6,2!" rem set "today=%mydate:~0,8%" /f "delims=" %%a in ('dir "d:\11\*.*" /b ^|find /v ".%today%-" ') ( echo "%%~fa" ) pause
Comments
Post a Comment