Page 1 of 1

Batch log file compressing?

Posted: 10 Nov 2011 07:57
by Wolf_22
Hi all. I have a quick question about compressing a bunch of log files that have specific years at the end of their file names...

Let's say I have the following set of files needing to be archived by year:
BVC2v2Batch.01042008.log
BVC2v2Batch.02042008.log
BVC2v2Batch.01042009.log
BVC2v2Batch.02042009.log
BVC2v2Batch.03042009.log
BVC2v2Batch.01042010.log
BVC2v2Batch.02042010.log
BVC2v2Batch.01042011.log
...

What I need is to basically place each group prior to 2010 inside their own year's ZIP folder. So for example, everything with the year of 2008 would be in bvc2008.zip, 2009 would be in bvc2009.zip, etc. Each year's log files inside their year's ZIP folder.

So below is where I am right now:

Code: Select all

@ECHO OFF
CLS

::
:: If the archives directory doesn't exist, create it...
::
:START
@ECHO "Step 1..."
IF NOT EXIST archives GOTO CREATE_DIR


::
:: Subroutine to create archives directory...
::
:CREATE_DIR
@ECHO "Step 2..."
MKDIR archives


::
:: Initialize main routine...
:: Notes: ~n excludes the file extension.
::
:INITIALIZE
@ECHO "Step 3..."
FOR %%G IN (*.log) DO (CALL :PARSE %%~nG)
PAUSE


::
:: Parse filename...
:: Notes: This parses names based on the number of characters the file name has. The first IF looks for 20-counts.
::        The next IF looks for 24-counts.
::
:PARSE
SET filename=%1
IF %filename:~0,20% == %filename% (
   @ECHO %filename:~16,4%
)
IF %filename:~0,24% == %filename% (
   @ECHO %filename:~20,4%
)
EXIT /b


When the above is executed, it looks for an "archives" folder. If it's not there, it tries to create it as a place to store the yearly ZIP archives. Beyond that, it just goes through steps of reading the file names and parsing the name itself if and only if they're of type *.log. As you can see, I'm still working on this but wanted to just pick your brains about whether I'm going down the right path here and to also understand why "ECHO is off." keeps getting repeated during runtime... It has me stumped. Why does it do this?

Any help with this is appreciated.