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

devoinr1970Asked:
Who is Participating?
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 PrewCommented:
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\DataFiles_20130903.zip c:\Users\Devoin\testfolder\*.doc

Open in new window

~bp
0

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
mankowitzCommented:
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

0
Bill PrewCommented:
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
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

"%ProgramFiles%\WinZip\winzip64"
0
Bill PrewCommented:
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
0
mankowitzCommented:
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.
0
devoinr1970Author Commented:
Thank you very much for your help. This worked greated
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.