Solved

Batch File - Zip files in current folder

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Starting up a Project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

632 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