Solved

Batch File - Zip files in current folder

Posted on 2013-06-03
2
856 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now