Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: batch DOS
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 Smile | :)
Posted 20-Feb-13 16:04pm

1 solution

Rate this: bad
good
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):
http://en.wikipedia.org/wiki/Windows_Script_Host[^].
 
You can find a good number of code samples, this is just one of them: http://stackoverflow.com/questions/11100696/how-to-compress-in-a-batch-file[^].
 
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:\someArchive.zip
 
You can also easily use WSH through PowerShell, without using VBScript or JavaScript:
http://en.wikipedia.org/wiki/Powershell[^].
 
If you are interested how to do it with PowerShell, I'll need some time to find a references, so please ask about it.
 
—SA
  Permalink  
Comments
Luiey Ichigo at 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 Application.zip (example)..is it possible? or I just copy the file into new folder and compress the new folder only?
 
What's your recommended?
Sergey Alexandrovich Kryukov at 21-Feb-13 0:32am
   
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:
 
http://www.techcoil.com/blog/handy-vbscript-functions-for-dealing-with-zip-files-and-folders/
 
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.
 
—SA

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
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