enrii.blog

A passionate programmer’s findings in the world of internet.

Zip a Folder Using Command Line

June 6th, 2007

As far as I know, the built-in compressed zip folder function in Windows XP does not provide any command line tools. To zip a folder using batch script or command line, one can install command line tool provided by 7zip.

It can be done with installation of whole 7zip package or just use an executable file provided by 7zip. I prefer the latter option.

Download the "7-Zip Command Line Version" from 7zip download page and unzip it.

Use the following command to zip a folder:

7za a -tzip <archive-name> <folder-name>

e.g. 7za a -tzip test.zip "New Folder"

Although this seems to be quite useless to be run in command line, but it's extremely useful if you need to create batch script to automatically zip a folder. For my case, I need it to zip a folder and FTP it to a server. By this way, I can backup a folder to server without having to consider the recursive FTP upload problem.

If my article helped you solved your problem, consider buy me a beer!

Share this article: del.icio.us | digg it

Tags: ,

Related posts:

10 Responses


Chochem says:

“For my case, I need it to zip a folder and FTP it to a server. By this way, I can backup a folder to server without having to consider the recursive FTP upload problem.”

Maybe I’m missing something here, but are you implying that 7zip _itself_ contains a command line ftp client? I havent been able to get it to do that (all i’ve found is that the help file claims it can email the file by the switch -seml – what it really does is attach it to an email draft and then leave you to do the rest 🙁 ) so please share this 🙂


EngLee says:

I’m using Windows FTP client to do the job. All I have to do is just to write a script to zip the folder with 7zip, then upload by calling an FTP script.

See this guide to know more about using FTP script with Windows FTP client: Using FTP Batch Scripts

Hope that helps.


anonymous says:

Hey thanks for this. This really did really come in handy.


Rakesh Suryavardhan says:

I’m new to batch files. i need to crate a batch file
to zip web folders(sampleone.com,sample2.com[folders])and upload to FTP. I am really confused now…Hope u will help me. Thanks in advance


radu says:

Excellent. Thanks man!


Rihan Meij says:

This is how you can do it:

for /D %f in (“*”) DO “7z” a -tzip archive.zip %f


joab says:

Thanks for sharing maestro. This really help me solved my problem. Great!!


Dinesh says:

Hi
I have zipped files, how do i unzip this file from commandline. Colud you please help me in resolving this issue. Thanks in advance


Paul says:

Hi,
This looks good! I have a requirement that i would appreciate help on if anyone can…
I have a folder structure like this:
parent folder
sub folder1
sub folder2
etc

I need to automate zipping the contents of the sub folders and create the zip file within that sub folder, and named the same as the folder.
So the contents of “sub folder1” should all be zipped and the zip file should be saved in “sub folder1” and called subfolder1.zip.

Do you know if this can be done?


mudassir says:

hi,
This does helpful for me…thanks for the help..
Thanks and appreciated