Solved

Batch File - Zip files in current folder

Posted on 2013-06-03
2
864 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.

820 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