i wrote this script to file previous month’s sametime chat logs (we used the reference chat logging dll which writes to text files). it places the chat logs in a directory hierarchy of year (4 digits) and month (2 digits with padding).

stcf.bat:

@ECHO OFF
CLS
:: SameTime Chatlog Filer (stcf)
:: purpose: Moves previous month's logs into sub dir e.g. Jan 2009 logs into
::          a directory called d:\chatlogs\2009\01
SETLOCAL EnableDelayedExpansion
SET chatLogsDir=D:\CHATLOGS\

SET DD=%date:~0,2%
SET MM=%date:~3,2%
:: Testing for first and last months of the year
::SET MM=01
::SET MM=12
SET YYYY=%date:~6,4%

:: Work out previous month's log file name, as we'll only be moving these log files
IF "%MM%" == "01" SET prevMon=DEC
IF "%MM%" == "02" SET prevMon=JAN
IF "%MM%" == "03" SET prevMon=FEB
IF "%MM%" == "04" SET prevMon=MAR
IF "%MM%" == "05" SET prevMon=APR
IF "%MM%" == "06" SET prevMon=MAY
IF "%MM%" == "07" SET prevMon=JUN
IF "%MM%" == "08" SET prevMon=JUL
IF "%MM%" == "09" SET prevMon=AUG
IF "%MM%" == "10" SET prevMon=SEP
IF "%MM%" == "11" SET prevMon=OCT
IF "%MM%" == "12" SET prevMon=NOV

ECHO DEBUG: %DD% %MM% %YYYY% %prevMon%

IF "%MM%" == "01" (
	SET prevMM=12
	SET /A YYYY=%YYYY%-1
)

IF "%MM%" == "02" SET prevMM=01
IF "%MM%" == "03" SET prevMM=02
IF "%MM%" == "04" SET prevMM=03
IF "%MM%" == "05" SET prevMM=04
IF "%MM%" == "06" SET prevMM=05
IF "%MM%" == "07" SET prevMM=06
IF "%MM%" == "08" SET prevMM=07
IF "%MM%" == "09" SET prevMM=08
IF "%MM%" == "10" SET prevMM=09
IF "%MM%" == "11" SET prevMM=10
IF "%MM%" == "12" SET prevMM=11

SET chatLogsDirDate=%chatLogsDir%%YYYY%\%prevMM%
ECHO MD %chatLogsDirDate%
ECHO MOVE %chatLogsDir%*%prevMon%*.dat %chatLogsDirDate%\
Tagged with:
 

Comments are closed.