Solved

Batch File - Zip files in current folder

Posted on 2013-06-03
2
865 Views
Last Modified: 2013-11-13
I 'm working with a batch file to zip up logs and clear the folder. I need help in adding code to not zip files with the current date (date -1).

Below is the code I am using to zip up the logs:

************************
set FILETOZIP=c:\Users\me.you\Downloads\*.*

    set TEMPDIR=C:\Users\me.you\temp1234

    rmdir %TEMPDIR%

    mkdir %TEMPDIR%

    copy %FILETOZIP% %TEMPDIR%

    echo Set objArgs = WScript.Arguments > _zipIt.vbs

    echo InputFolder = objArgs(0) >> _zipIt.vbs

    echo ZipFile = objArgs(1) >> _zipIt.vbs

    echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs

    echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs

    echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs

    echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs

    echo wScript.Sleep 2000 >> _zipIt.vbs

    CScript  _zipIt.vbs  %TEMPDIR%  C:\Users\me.you\Testing.zip

    cd “%TEMPDIR%”

   del *.* /Q

cd \

rmdir %TEMPDIR%

cd /d “C:\Users\me.you\Downloads

del *.* /Q
0
Comment
Question by:adkdavis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
John-Charles-Herzberg earned 500 total points
ID: 39215973
If you are using 7-zip this might help:

Note: 7-Zip which is free and easy to use application that has a self-contained command line version (7za.exe).

Here's a two-line batch file that would zip the txt files and delete them afterwards:
7za.exe a -tzip ex%1-backup.zip %2\ex%1*.log
del %2\ex%1*.txt

To run batch file: variable/parameter is 4 digits year-and-month YYMM, and the second parameter is the path to the directory containing the files to backup/zip. For example: backup.bat 1306 c:\files

Thanks
JC
0
 

Author Comment

by:adkdavis
ID: 39216841
I appreciate the solution, but unfortunately we are only authorized to use approved winzip on our systems. Also, the files that I need to exclude from zipping are the current days  log....I can zip the previous days of the month (needing to check the date with this format -MMDDYYYY). Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question