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\ 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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Anytime a path has spaces in it you need to enclose it in quotes in a BAT script, so I think this might be a problem with the ZIP command line.  Also, you want to get the free command line addon for WinZip and use that rather than the GUI program.

"C:\Program Files\WZZIP" -a c:\Users\Devoin\TestSSIS\ c:\Users\Devoin\testfolder\*.doc

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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\ @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

Bill PrewIT / Software Engineering ConsultantCommented:
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:

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.

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

NVITEnd-user supportCommented:
> ...for some reason I cannot get the script to zip the files.
Check C:\Program Files\WINZIP64
Is that the correct .exe name?
Steven CarnahanNetwork ManagerCommented:
If WinZip is installed with defaults it would be:

Bill PrewIT / Software Engineering ConsultantCommented:
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...

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\ @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.
devoinr1970Author Commented:
Thank you very much for your help. This worked greated
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.