Link to home
Start Free TrialLog in
Avatar of devoinr1970
devoinr1970

asked on

Creating script that will zip file every 15 days

I'm creating a script which will zip all doc files in 1 directory, which are 15 days old. I'm using winzip64, but for some reason I cannot get the script to zip the files. Also, after the files have been zip for 45 days I want to delete the zipped files. below is my script, but I have not added the date checks. I would like help creating the date check and finding out why this code will not zip the files.

@echo off
if exist "c:\Users\Devoin\testfolder\*.doc*" (
echo. File Exists
C:\Program Files\WINZIP64 -a c:\Users\Devoin\TestSSIS\DataFiles_20130903.zip c:\Users\Devoin\testfolder\*.doc

REM xcopy c:\Users\Devoin\testfolder\*.doc* c:\Users\Devoin\TestSSIS
REM del c:\Users\Devoin\testfolder\*.doc*
REM pause
REM exit

) else (
echo Random Text >>"c:\Users\Devoin\testfolder\*.doc*"
 REM exit
)

goto :EOF

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try something like this to zip all the 15 day old files:

forfiles /p "C:\Users\Devoin\testfolder" /s /d -15 /m *.doc* /c "cmd /c C:\Program Files\WINZIP64 -a c:\Users\Devoin\TestSSIS\DataFiles_20130903.zip @path"

Open in new window

and this to delete the old ones

forfiles /p "c:\Users\Devoin\TestSSIS\" /s /m *.zip /c "cmd /c Del @path" /d -45

Open in new window

Avatar of Bill Prew
Bill Prew

If you can use a third party utility, the easiest way to clean up the old files could be DELAGE32, take a look at it at:

http://www.horstmuc.de/wbat32.htm
http://www.horstmuc.de/win/delage.htm

If not then we could use FORFILES in the BAT script to do it (which you might already have on Windows if it's recent). or could even do it with pure DOS BAT command, but that is a bit more complicated - BAT not great as date math.

~bp
> ...for some reason I cannot get the script to zip the files.
Check C:\Program Files\WINZIP64
Is that the correct .exe name?
If WinZip is installed with defaults it would be:

"%ProgramFiles%\WinZip\winzip64"
Why wouldn't we be using the WZZIP command line tool for WinZip (free) from a batch script, rather than the UI version of the program (WINZIP64.EXE)?  I never do that...

~bp
The following worked for me:

C:\Users\sm> forfiles /p C:\Users\sm\Documents\Correspondence /s /d -15 /m *.doc* /c "cmd /c C:\Progra~1\WinZip\wzzip.exe -a C:\Users\sm\Documents\Correspondence\stor.zip @path"

Open in new window


Note that cmd has a problem with "program files" and gets confused about the first and second argument, so I reverted back to the dos naming scheme.
Avatar of devoinr1970

ASKER

Thank you very much for your help. This worked greated