Batch script to zip file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rajesherg
Posts: 1
Joined: 09 Feb 2014 01:00

Batch script to zip file

#1 Post by rajesherg » 09 Feb 2014 01:10

I am new to windows bat script. I have situation where I have a files coming in folder
D:\Source
with files such as
code_gen_text_111.txt
code_gen_text_222.txt

The windows script should generate zip files with same name in the same folder and also delete the existing txt file.

Example, result should be

code_gen_text_111.zip
code_gen_text_222.zip in folder D:\Source.

Can someone help me in providing the entire script to achieve this?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to zip file

#2 Post by foxidrive » 09 Feb 2014 04:58

How do you want them zipped? Using which program?

Do you know the command line of the ZIP program?

Multi-posted: http://stackoverflow.com/questions/2165 ... bat-script

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: Batch script to zip file

#3 Post by xhai » 26 Feb 2014 22:06

rajesherg wrote:I am new to windows bat script. I have situation where I have a files coming in folder
D:\Source
with files such as
code_gen_text_111.txt
code_gen_text_222.txt

The windows script should generate zip files with same name in the same folder and also delete the existing txt file.

Example, result should be

code_gen_text_111.zip
code_gen_text_222.zip in folder D:\Source.

Can someone help me in providing the entire script to achieve this?


Code: Select all

::simple code by xhai
echo off
:Archieve
set archievePatch=txt1.txt
set archievePatch2=txt2.txt
7z.exe a txt1.zip "%archievePatch%"
7z.exe a txt2.zip "%archievePatch2%"
DEL /F /Q "txt1.txt"
DEL /F /Q "txt2.txt"
PATH D:\Source
pause
exit


You need to Install the latest 7zip. copy the files in the same folder and run the .bat program
7z.dll
7z.exe
7-zip.dll

or

change 7z.exe a txt1.zip "%archievePatch%" to C:\Users\xhai>7z.exe a txt1.zip "%archievePatch%"

other might revise or improve the code because i'm still noob in here..

people here are helping me so i'm doing the best i can to help other's

Post Reply