Anyone around here know Windows BATCH code?

I’m trying to create a minor batch process that reads the current directory for log files and parses each file that is found by the last 4 characters (the year) in the file’s name.

I.e. -

record.01042008.log
record.01052008.log
record.01062008.log
record.01072008.log

record.01042009.log
record.01042010.log
record.01042010.log
record.01042011.log

I’d like to take each file that matches a given year, say 2010, and take each of these and archive it into a *.ZIP file. In other words, I’m just trying to zip-up all 2010 log files…

Here’s where I am right now:


@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...
::
:INITIALIZE
ECHO "Step 3..."
FOR %%G IN (*.log) DO (CALL :PARSE %%G)
PAUSE

::
:: Parse filename...
::
:PARSE
ECHO %1
EXIT /b

The token and delims modifiers / switches don’t work when I include them causing the entire batch file to simply not work. Any insight into this is appreciated.

Off Topic:

Not bashing SP or anything, but does anyone know what’s up with this new theme? This white / bleach-bone coloring scheme really stinks. It’s hard to make the distinction at times between input forms and overall website controls… Any word on this?

If you could use powershell to handle this it would be alot easier. Failing that I’d advise using vbscript. I think you might be able to figure out how to do it using MS dos batch files but they aren’t really meant for this sort of thing.

Check the general announcements section for more than you ever wanted to hear about the redesign/forum update.

I went with the batch route because I thought that using Windows Server 2003’s “Scheduled Tasks” to do this would be as easy as it gets. If I go with something like VBScript, how would I implement it inside that environment? I’ve worked with VBScript before but it was with things like PHP and Excel files… Not batch processing. :-\

We run lots of powershell on Windows Server 2003, and we’ve done a bit of vbs. Key trick is that you can pass the script to execute and other commands by calling:

WSH: cscript [script file name]
Powershell: powershell [script file name]

Run either command from the command prompt with a /? to get a full list of commands.

If all you want to do is zip some files as you described, you just need java installed and a zipStuff.cmd (or .bat) file with:

jar cvf My%1Archive.zip *%1.log

in it.

Call it with: zipStuff 2010 to zip all 2010 logs into My2010Archive.zip, for instance.

If you can figure out the command line commands for <zip program of your choice>, you could do the same thing without having Java installed.