Leptonator
Leptonator

Reputation: 3529

Batch file to zip Apache Tomcat for windows file names that do not equal to today

We have a number of Apache Tomcat for Windows logs - for 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 are defined with a file extension of .YYYY-MM-DD-HH and by default Apache has them by date: .YYYY-MM-DD however, we have to define the HH breakover because of system usage and other reasons. I am trying to do something very simple.. If the file extension does not equal today, to archive (zip) it up..

Here is what I have and no matter what I do is that it shows: 2014-02-05 even though the script is showing .2014-02-04.

Here is the script and I am not sure if I need SETLOCAL enabledelayexpansion..

rem http://www.dostips.com/DtTipsStringManipulation.php#Snippets.Replace
SETLOCAL enabledelayedexpansion
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
set today=!MyDate:~0,4!-!MyDate:~4,2!-!MyDate:~6,2!
rem today=%MyDate:~0,8%
for %%i in (D:\11\*.*) do (
SET FILETIME=%%~xi
rem SET Dt=!FILETIME:~0,11!
rem IF NOT "!fldt!" == ".!today!" (
rem echo %%~ni%%~xi
rem )
)
pause

Thanks

Upvotes: 0

Views: 80

Answers (1)

foxidrive
foxidrive

Reputation: 41307

This filters the filenames by the date string in the name and
will echo the filenames that do not have todays date in them.

@echo off
rem http://www.dostips.com/DtTipsStringManipulation.php#Snippets.Replace
SETLOCAL enabledelayedexpansion
for /f %%x in ('wmic os get localdatetime ^|find "." ') do set "MyDate=%%x"
set "today=!MyDate:~0,4!-!MyDate:~4,2!-!MyDate:~6,2!"
rem set "today=%MyDate:~0,8%"
for /f "delims=" %%a in ('dir "D:\11\*.*" /b ^|find /v ".%today%-" ') do (
   echo "%%~fa"
)
pause

Upvotes: 1

Related Questions