Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File - Zip files in current folder

Posted on 2013-06-03
2
Medium Priority
?
875 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 1500 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Six Sigma Control Plans
Introduction to Processes

688 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