Posted on 2005-02-25
Not really sure how to title this... here's a little background.
I play this online baseball game and after each 2/3/4 game series I have to send data files, renamed and compressed, to the members of my league. Typically, this has been done manually. But there's no good reason I can think of that won't allow me to script it - only I'm lacking a certain degree of understanding in a key area and need some help (figuring SteveGTR, sirbounty, or DrWarezz are my best hopes, but anyone is welcome to comment).
In any case, note the script I have so far (lots of comments explaining what I need/am trying to do).
REM Check for the existance of %1
if "%1" == "" Goto ErrNoTeam
REM Set the visitor to env. var. to %1 (should be a 3 letter code)
REM For testing any 3 letter code will do, but BKA is the first I'm using myself.
REM Set my home team env. var. to my 3 letter code.
REM Define the initial zip filename
REM Change to directory with the data files
cd /d c:\cdrombb\export
REM Zip the data files into the zip file using InfoZip Command line.
zip -9 "%zipfile%" 2005WB*.*
REM Check for the existance of the packed directory - if not there, create it.
If Not Exist .\packed md .\packed
REM Move the previously zipped data files to the packed directory so they are
REM not referenced again.
move 2005wb*.* .\packed
REM Move the zipfile to the print directory containing the text files
move "%zipfile%" ..\print\2005wb
REM Change into the print directory.
REM Get a list of all boxscore print (box*.prt) files - each must be renamed
REM based on information found within the file. I order from newest to oldest
REM because the oldest should be the first game and the zip file must be
REM renamed one more time to oldestgame %zipfile% - so in theory, the last
REM %gamedate% set should be the oldest date.
for /f "tokens=1 delims=" %%a in ('dir /o-d /b box*.prt') Do Call :ProcessGames %%a
REM Rename the zipfile to the final filename.
ren "%zipfile%" "%GameDate% %zipfile%"
REM Script now complete.
REM This is my biggest problem area. I can't seem to get this part to work
REM right. I've had it seemingly skip the first file then correctly process the
REM the second two, setting gamedate correctly on those.
REM This needs to be run for each game. It should find the line starting with
REM "]BOXSCORE: " in the file %1 and then set the GameDate env. var. to the
REM last 9 characters of the line. Ideally, it will also remove any leading
REM and trailing spaces. Lastly, the GameDate needs to be in a mmddyy format
For /f "tokens=1 skip=2 delims=" %%m in ('find "]BOXSCORE: " %1') Do (
Echo Could not complete packing - you did not specify your opponant!
Now, for your sample box*.prt files, the line of data retrieved looks like this for each file:
C:\CDROMBB\Print\2005WB>find "BOXSCORE" BOX*.PRT
BOXSCORE: 2005 Brookhurst Spartans At 2005 Sunnydale Vengence Demon 4/16/2005
BOXSCORE: 2005 Brookhurst Spartans At 2005 Sunnydale Vengence Demon 4/17/2005
BOXSCORE: 2005 Brookhurst Spartans At 2005 Sunnydale Vengence Demon 4/18/2005
Also, file info:
Volume in drive C has no label.
Volume Serial Number is A816-3E28
Directory of C:\CDROMBB\Print\2005WB
02/25/2005 04:34 AM 6,695 BOX0069.prt
02/25/2005 05:12 AM 8,946 BOX0070.prt
02/25/2005 05:44 AM 7,335 BOX0071.prt
The end result should be:
Old file name --> new file name through script
BOX0069.PRT --> 041605 BKA@SUN.PRT
BOX0070.PRT --> 041705 BKA@SUN.PRT
BOX0071.PRT --> 041805 BKA@SUN.PRT
The final zip file name should be:
However you can get this working, I'll take it. (It's gonna be run 50+ times by me in the next 6 months and MAYBE by 19 other guys too) I figure most of it doesn't need to be edited, just that ProcessGames section. Thanks all!