Click here to Skip to main content
13,089,504 members (60,768 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

Does anyone know the command line to compress a folder to zip? Like on our default Windows OS, even we don't install 3rd party software to compress, we also can compress the folder by right click the folder/file and Send To --> Compressed (Zipped)

Is it possible to compress the folder? I don't want to install any 3rd party software to compress. I want to use Windows Compressed. If anyone here know the link, kindly give me..tq :)
Posted 20-Feb-13 15:04pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you really want to do it without using any 3-rd party compress utility, with just the batch, you can use Windows Script Host (WSH):[^].

You can find a good number of code samples, this is just one of them:[^].

The sample of batch file for this script is just one line (in case you did not recognize it):
CScript zip.vbs C:\test3 C:\

You can also easily use WSH through PowerShell, without using VBScript or JavaScript:[^].

If you are interested how to do it with PowerShell, I'll need some time to find a references, so please ask about it.

Luiey Ichigo 20-Feb-13 22:10pm
Hi Sergey,

I already use the code from your link at stakeflow by running the batch with vb script anddddddddd it's work. thank man. you rock. +5 for u..

I've no experience in PowerShell. Looking to it's code make me feel dizzy. LOL :) better with vbs

Instead of that, the compress only folder, but what if i want to compress multi extension file in a single compress. Means *.dll and *.ini will be compress into (example) it possible? or I just copy the file into new folder and compress the new folder only?

What's your recommended?
My pleasure. If so, will you accept the answer formally (green button)?

As to PowerShell, it needs some attention and time to get into it. I'll tell you, I never saw anything better, in terms of the beauty and convenience of scripting language (of course, no need to compare with compiling languages), debugger, and the method of binding the APIs. One just need to get familiar with that stuff. I was myself very skeptical, before v.3.

However, even batch language, despite the brain-damaging features and lack of debugging, is better then many think; did you know that it even got method calls?

Now, compressing... What's the problem? Not to create an intermediate directory? I think, it's possible; you can use the directory where the zip file is supposed to be created.

Look at this sample:

zip.CopyHere works with Variant d.Items representing items to be packed. You can calculate it in VBScript or JavaScript based on the criteria you want, say, collect item by item in a loop, or something like that.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100