# Batch File using WinZip



## MorPhiend (Nov 3, 2005)

I need help writing a batch file. Parts are quite complicated for me, as I have no background in batch commands. But hopefully this is an easy problem for someone here. I have gotten part of it to work so far.

What I need to accomplish is:

1) Copy a list of .xls files for the current date from a shared folder on a remote server to my local HDD whose file names end with YYYYMMDD.
2) Use WinZip to add these daily files to existing zips of the same name, minus the date.
3) Export the updated zips out to multiple servers to replace the previous day's zips.
4) Delete the oldest .xls file from the zips on my local HDD.
5) Add the current date's .xls files on my HDD to archive zips of the same name ending with a date range "_Archive_YYYYMMDD-YYYYMMDD.zip".
6) Rename the archive zips to replace the last date with the current date.
7) Delete the current date's .xls files from my HDD.

I have steps 1, 2, 3 and 7 taken care of. I've taken a few swings at numbers 5 and 6, but since the goal is to have the date range always changing, I haven't been able to figure it out using a wildcard. I'm not sure if number six is possible unless there is a command to truncate the last certain number of characters in a name. But Google hasn't been helpful with 4, 5 and 6 for me.

Here is a couple samples of the steps I have gotten to work:

```
xcopy "\\remoteserver\targetfolder\samplefile_%date:~10,4%%date:~4,2%%date:~7,2%.xls" "C:\zipArchives\"

xcopy "\\remoteserver\targetfolder\samplefile2_%date:~10,4%%date:~4,2%%date:~7,2%.xls" "C:\zipArchives\"

set LOG_FILE_NAME=samplefile_%date:~10,4%%date:~4,2%%date:~7,2%.xls
"C:\program files\winzip\WINZIP32.EXE" -min -a "C:\zipArchives\samplefile.zip" C:\zipArchives\%LOG_FILE_NAME%

set LOG_FILE_NAME=samplefile2_%date:~10,4%%date:~4,2%%date:~7,2%.xls
"C:\program files\winzip\WINZIP32.EXE" -min -a "C:\zipArchives\samplefile2.zip" C:\zipArchives\%LOG_FILE_NAME%

xcopy "C:\zipArchives\samplefile.zip" "\\remoteserver\targetfolder\samplefile.zip" /y
xcopy "C:\zipArchives\samplefile.zip" "\\remoteserver2\targetfolder\samplefile.zip" /y
xcopy "C:\zipArchives\samplefile.zip" "\\remoteserver3\targetfolder\samplefile.zip" /y
xcopy "C:\zipArchives\samplefile.zip" "\\remoteserver4\targetfolder\samplefile.zip" /y

xcopy "C:\zipArchives\samplefile2.zip" "\\remoteserver\targetfolder\samplefile2.zip" /y
xcopy "C:\zipArchives\samplefile2.zip" "\\remoteserver2\targetfolder\samplefile2.zip" /y
xcopy "C:\zipArchives\samplefile2.zip" "\\remoteserver3\targetfolder\samplefile2.zip" /y
xcopy "C:\zipArchives\samplefile2.zip" "\\remoteserver4\targetfolder\samplefile2.zip" /y

del C:\zipArchives\samplefile_*.xls

del C:\zipArchives\samplefile2_*.xls
```
I don't know if I'm being inefficient on any of those steps. Feel free to inform me of easier steps or extra things that didn't need to be typed.

And here's my attempts and steps 5 and 6:

```
"C:\program files\winzip\WINZIP32.EXE" -min -a "C:\zipArchives\samplefile\samplefile_Archive*.zip" C:\zipArchives\samplefile_*.xls

ren C:\zipArchives\samplefile\samplefile_Archive_20120106-*.zip samplefile_20120106-%date:~10,4%%date:~4,2%%date:~7,2%
```
The errors for each are:
WinZip error - Filename of archive not complete. Be sure to specify a valid filename.
The system cannot find the file specified.

On that rename step, I don't know if there is a truncate option, but that would be nice so that I don't have to maintain a list of different start dates for all of the zips since I maintain a list of different files and new ones are being started and old ones retired quite often.

TIA for any help.


----------



## Squashman (Apr 4, 2003)

Well of course #6 is possible. You are already doing string manipulation by position and size with the date command.


----------

