Can you zip a file from the command prompt using ONLY Windows' built-in capability to zip files?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







98















I have a batch file that outputs a text file. I thought it would be nice if I could zip it up too.



This will be used in an uncontrolled environment, so I can't make assumptions about the presence of third-party software products such as 7-Zip, etc. This needs to use Windows' now-built-in capability to zip files.










share|improve this question




















  • 1





    can you utilize Powershell or WSH scripting? that might be the only way to use Windows' builtin zip handling from the commandline. otherwise, as Molly points out, you need a 3rd-party tool.

    – quack quixote
    Feb 19 '10 at 19:59








  • 1





    so you send someone a batch file and you can not send him some tiny statically linked gzip.exe?

    – akira
    Feb 19 '10 at 22:16











  • The OP's question is an excellent one (@quackquixote 's strange accusation notwithstanding). Since Windows does provide this as a single click under SendTo, there ought to be a command usable in a BAT file. So it's a good question even if the answer is No and one has to (ridiculously) resort to using a third-party tool that may or may not be equivalent.

    – Jon Coombs
    Dec 24 '14 at 0:33











  • This is link by Tomas has a well written script to zip contents of a folder. To make it work just copy the script into a batch file and execute it by specifying the folder to be zipped(source). No need to mention destination directory as it is defaulted in the script to Desktop ("%USERPROFILE%Desktop")

    – Abhijeet
    Jan 11 '16 at 2:46








  • 2





    The simpliest would be, in a cmd prompt : powershell.exe Compress-Archive file-to-zip.txt zippedfile.zip (it works with folder too)

    – ThomasGuenet
    Sep 5 '17 at 8:33




















98















I have a batch file that outputs a text file. I thought it would be nice if I could zip it up too.



This will be used in an uncontrolled environment, so I can't make assumptions about the presence of third-party software products such as 7-Zip, etc. This needs to use Windows' now-built-in capability to zip files.










share|improve this question




















  • 1





    can you utilize Powershell or WSH scripting? that might be the only way to use Windows' builtin zip handling from the commandline. otherwise, as Molly points out, you need a 3rd-party tool.

    – quack quixote
    Feb 19 '10 at 19:59








  • 1





    so you send someone a batch file and you can not send him some tiny statically linked gzip.exe?

    – akira
    Feb 19 '10 at 22:16











  • The OP's question is an excellent one (@quackquixote 's strange accusation notwithstanding). Since Windows does provide this as a single click under SendTo, there ought to be a command usable in a BAT file. So it's a good question even if the answer is No and one has to (ridiculously) resort to using a third-party tool that may or may not be equivalent.

    – Jon Coombs
    Dec 24 '14 at 0:33











  • This is link by Tomas has a well written script to zip contents of a folder. To make it work just copy the script into a batch file and execute it by specifying the folder to be zipped(source). No need to mention destination directory as it is defaulted in the script to Desktop ("%USERPROFILE%Desktop")

    – Abhijeet
    Jan 11 '16 at 2:46








  • 2





    The simpliest would be, in a cmd prompt : powershell.exe Compress-Archive file-to-zip.txt zippedfile.zip (it works with folder too)

    – ThomasGuenet
    Sep 5 '17 at 8:33
















98












98








98


45






I have a batch file that outputs a text file. I thought it would be nice if I could zip it up too.



This will be used in an uncontrolled environment, so I can't make assumptions about the presence of third-party software products such as 7-Zip, etc. This needs to use Windows' now-built-in capability to zip files.










share|improve this question
















I have a batch file that outputs a text file. I thought it would be nice if I could zip it up too.



This will be used in an uncontrolled environment, so I can't make assumptions about the presence of third-party software products such as 7-Zip, etc. This needs to use Windows' now-built-in capability to zip files.







windows command-line batch zip






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 16 '13 at 8:29









Peter Mortensen

8,386166185




8,386166185










asked Feb 19 '10 at 19:46









Aaron BushAaron Bush

613177




613177








  • 1





    can you utilize Powershell or WSH scripting? that might be the only way to use Windows' builtin zip handling from the commandline. otherwise, as Molly points out, you need a 3rd-party tool.

    – quack quixote
    Feb 19 '10 at 19:59








  • 1





    so you send someone a batch file and you can not send him some tiny statically linked gzip.exe?

    – akira
    Feb 19 '10 at 22:16











  • The OP's question is an excellent one (@quackquixote 's strange accusation notwithstanding). Since Windows does provide this as a single click under SendTo, there ought to be a command usable in a BAT file. So it's a good question even if the answer is No and one has to (ridiculously) resort to using a third-party tool that may or may not be equivalent.

    – Jon Coombs
    Dec 24 '14 at 0:33











  • This is link by Tomas has a well written script to zip contents of a folder. To make it work just copy the script into a batch file and execute it by specifying the folder to be zipped(source). No need to mention destination directory as it is defaulted in the script to Desktop ("%USERPROFILE%Desktop")

    – Abhijeet
    Jan 11 '16 at 2:46








  • 2





    The simpliest would be, in a cmd prompt : powershell.exe Compress-Archive file-to-zip.txt zippedfile.zip (it works with folder too)

    – ThomasGuenet
    Sep 5 '17 at 8:33
















  • 1





    can you utilize Powershell or WSH scripting? that might be the only way to use Windows' builtin zip handling from the commandline. otherwise, as Molly points out, you need a 3rd-party tool.

    – quack quixote
    Feb 19 '10 at 19:59








  • 1





    so you send someone a batch file and you can not send him some tiny statically linked gzip.exe?

    – akira
    Feb 19 '10 at 22:16











  • The OP's question is an excellent one (@quackquixote 's strange accusation notwithstanding). Since Windows does provide this as a single click under SendTo, there ought to be a command usable in a BAT file. So it's a good question even if the answer is No and one has to (ridiculously) resort to using a third-party tool that may or may not be equivalent.

    – Jon Coombs
    Dec 24 '14 at 0:33











  • This is link by Tomas has a well written script to zip contents of a folder. To make it work just copy the script into a batch file and execute it by specifying the folder to be zipped(source). No need to mention destination directory as it is defaulted in the script to Desktop ("%USERPROFILE%Desktop")

    – Abhijeet
    Jan 11 '16 at 2:46








  • 2





    The simpliest would be, in a cmd prompt : powershell.exe Compress-Archive file-to-zip.txt zippedfile.zip (it works with folder too)

    – ThomasGuenet
    Sep 5 '17 at 8:33










1




1





can you utilize Powershell or WSH scripting? that might be the only way to use Windows' builtin zip handling from the commandline. otherwise, as Molly points out, you need a 3rd-party tool.

– quack quixote
Feb 19 '10 at 19:59







can you utilize Powershell or WSH scripting? that might be the only way to use Windows' builtin zip handling from the commandline. otherwise, as Molly points out, you need a 3rd-party tool.

– quack quixote
Feb 19 '10 at 19:59






1




1





so you send someone a batch file and you can not send him some tiny statically linked gzip.exe?

– akira
Feb 19 '10 at 22:16





so you send someone a batch file and you can not send him some tiny statically linked gzip.exe?

– akira
Feb 19 '10 at 22:16













The OP's question is an excellent one (@quackquixote 's strange accusation notwithstanding). Since Windows does provide this as a single click under SendTo, there ought to be a command usable in a BAT file. So it's a good question even if the answer is No and one has to (ridiculously) resort to using a third-party tool that may or may not be equivalent.

– Jon Coombs
Dec 24 '14 at 0:33





The OP's question is an excellent one (@quackquixote 's strange accusation notwithstanding). Since Windows does provide this as a single click under SendTo, there ought to be a command usable in a BAT file. So it's a good question even if the answer is No and one has to (ridiculously) resort to using a third-party tool that may or may not be equivalent.

– Jon Coombs
Dec 24 '14 at 0:33













This is link by Tomas has a well written script to zip contents of a folder. To make it work just copy the script into a batch file and execute it by specifying the folder to be zipped(source). No need to mention destination directory as it is defaulted in the script to Desktop ("%USERPROFILE%Desktop")

– Abhijeet
Jan 11 '16 at 2:46







This is link by Tomas has a well written script to zip contents of a folder. To make it work just copy the script into a batch file and execute it by specifying the folder to be zipped(source). No need to mention destination directory as it is defaulted in the script to Desktop ("%USERPROFILE%Desktop")

– Abhijeet
Jan 11 '16 at 2:46






2




2





The simpliest would be, in a cmd prompt : powershell.exe Compress-Archive file-to-zip.txt zippedfile.zip (it works with folder too)

– ThomasGuenet
Sep 5 '17 at 8:33







The simpliest would be, in a cmd prompt : powershell.exe Compress-Archive file-to-zip.txt zippedfile.zip (it works with folder too)

– ThomasGuenet
Sep 5 '17 at 8:33












11 Answers
11






active

oldest

votes


















83














Here is an all batch file solution (a variation of my other answer) that will zip a file named c:ue_english.txt and put it in C:someArchive.zip:



set FILETOZIP=c:ue_english.txt

set TEMPDIR=C:temp738
rmdir %TEMPDIR%
mkdir %TEMPDIR%
xcopy /s %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:someArchive.zip

pause


Write access is required to the parent of the folder stored in TEMPDIR. As this is often not the case for the root of drive C TEMPDIR may have to be changed.



Write access is also required for the folder the .bat script is in (as it generates a file there).



Also, please note that the file extension for the compressed file must be .zip. Attempts to use another extension may result in a script error. Instead, generate the .zip file and rename it.






share|improve this answer





















  • 3





    @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

    – Aaron Bush
    Mar 2 '10 at 13:56













  • @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

    – Tom Wijsman
    Nov 29 '11 at 13:54













  • I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

    – erm3nda
    Dec 10 '13 at 6:59













  • Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

    – Nam G VU
    Oct 15 '14 at 2:11













  • @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

    – JohnG
    May 18 '16 at 16:21



















37














It is possible to zip files without installation of any additional
software (I have tested it). The solution is:



Run this in a command-line window to create a zip file
named C:someArchive.zip containing all files in folder C:test3:



CScript  zip.vbs  C:test3  C:someArchive.zip


Where file zip.vbs contains:



'Get command-line arguments.
Set objArgs = WScript.Arguments
Set FS = CreateObject("Scripting.FileSystemObject")
InputFolder = FS.GetAbsolutePathName(objArgs(0))
ZipFile = FS.GetAbsolutePathName(objArgs(1))

'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

Set objShell = CreateObject("Shell.Application")

Set source = objShell.NameSpace(InputFolder).Items

objShell.NameSpace(ZipFile).CopyHere(source)

'Required to let the zip command execute
'If this script randomly fails or the zip file is not complete,
'just increase to more than 2 seconds
wScript.Sleep 2000


I haven't tested it for paths and file names containing spaces. It may work if quotes
are put around the command line parameters.





How it works: the built-in zip functionality in Windows (Windows XP and later?) is
exposed through COM interfaces from the Windows shell
, explorer.exe - that is the "Shell.Application" part. This COM interface can be used from a VBScript script because
such a script can access COM components. To make the script fully self-contained it creates
an empty ZIP file to get started (one could also create an empty ZIP file and copy it to the target system along with the VBScript script).



VBScript has been installed by default in every desktop
release of Microsoft Windows since Windows 98.



CScript.exe is part of Windows Script Host.
Windows Script Host is distributed and installed by default on Windows 98 and later versions of Windows. It is also installed if Internet Explorer 5 (or a later version) is installed.






share|improve this answer





















  • 1





    +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

    – Aaron Bush
    Feb 22 '10 at 13:30








  • 4





    @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

    – quack quixote
    Feb 22 '10 at 23:24













  • Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

    – Chuck Wilbur
    Jun 27 '12 at 21:08











  • Paths have to be absolute and it seems to randomly fail :(

    – kixorz
    Feb 13 '14 at 20:33











  • This should be selected as the answer.

    – The Duke Of Marshall שלום
    Mar 14 '14 at 17:48



















12














If you are open to using PowerShell, zip capabilities are available in .NET 2.0 (PowerShell is .NET). Here's an a example (source) credit to Mike Hodnick:



########################################################
# out-zip.ps1
#
# Usage:
# To zip up some files:
# ls c:source*.txt | out-zip c:targetarchive.zip $_
#
# To zip up a folder:
# gi c:source | out-zip c:targetarchive.zip $_
########################################################

$path = $args[0]
$files = $input

if (-not $path.EndsWith('.zip')) {$path += '.zip'}

if (-not (test-path $path)) {
set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
}

$ZipFile = (new-object -com shell.application).NameSpace($path)
$files | foreach {$zipfile.CopyHere($_.fullname)}





share|improve this answer


























  • This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

    – Robert Schmidt
    Feb 25 '14 at 8:14








  • 2





    The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

    – Concrete Gannet
    Nov 24 '14 at 8:00



















7














You can eliminate the risk of timing out during compression by polling for existence of the compression dialog window. This method also handles the user cancelling out of the compression window.



objShell.NameSpace(ZipFile).CopyHere(source)

' Wait for compression window to open
set scriptShell = CreateObject("Wscript.Shell")
Do While scriptShell.AppActivate("Compressing...") = FALSE
WScript.Sleep 500 ' Arbitrary polling delay
Loop

' Wait for compression to complete before exiting script
Do While scriptShell.AppActivate("Compressing...") = TRUE
WScript.Sleep 500 ' Arbitrary polling delay
Loop





share|improve this answer





















  • 1





    +1. Those code monkey-style ".Sleep(whatever)" make me sick.

    – ivan_pozdeev
    Jun 25 '13 at 14:30








  • 1





    If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

    – Wes
    Jun 27 '13 at 22:05



















4














If you are able to install the Resource Kit Tools, you will find a command line tool called COMPRESS that can create compressed archive files like zip.



Microsoft (R) File Compression Utility  Version 5.00.2134.1
Copyright (C) Microsoft Corp. 1990-1999. All rights reserved.

Compresses one or more files.

COMPRESS [-r] [-d] [-z] Source Destination
COMPRESS -r [-d] [-z] Source [Destination]

-r Rename compressed files.
-d Update compressed files only if out of date.
-zx LZX compression.
-z MS-ZIP compression.
-zq[n] Quantum compression and optional level
(in range 1-7, default is 4).
Source Source file specification. Wildcards may be used.
Destination Destination file | path specification.
Destination may be a directory.
If Source is multiple files and -r is not specified,
Destination must be a directory.





share|improve this answer



















  • 2





    +1 Doesn't really solve things, but still good to know about.

    – Aaron Bush
    Feb 22 '10 at 13:28



















3














'Keep script waiting until compression is done
Do Until objShell.NameSpace( ZipFile ).Items.Count = objShell.NameSpace( InputFolder ).Items.Count
WScript.Sleep 200
Loop





share|improve this answer


























  • exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

    – Sonic Soul
    Apr 3 '14 at 21:25













  • For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

    – Thom Nichols
    Apr 27 '15 at 20:20



















2














Multiple files / directories with simplified code.



cscript zip.vbs target.zip sourceFile1 sourceDir2 ... sourceObjN


zip.vbs file



Set objArgs = WScript.Arguments
ZipFile = objArgs(0)

' Create empty ZIP file and open for adding
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

' Add all files/directories to the .zip file
For i = 1 To objArgs.count-1
zip.CopyHere(objArgs(i))
WScript.Sleep 10000 'REQUIRED!! (Depending on file/dir size)
Next





share|improve this answer

































    2














    This is a mutation of the accepted answer. I do a ton of automation tasks on up to thousands of files at a time, so I can't just sleep for 2 seconds and not care about it. I gleaned the workaround here, which is also similar to Jiří Kočara's answer here.



    This will cause the destination folder to be pinged every 200ms, which is approximately as fast as Microsoft says to check for FS updates.



    Set parameters = WScript.Arguments
    Set FS = CreateObject("Scripting.FileSystemObject")
    SourceDir = FS.GetAbsolutePathName(parameters(0))
    ZipFile = FS.GetAbsolutePathName(parameters(1))
    CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
    Set shell = CreateObject("Shell.Application")
    Set source_objects = shell.NameSpace(SourceDir).Items
    Set ZipDest = shell.NameSpace(ZipFile)
    Count=ZipDest.Items().Count
    shell.NameSpace(ZipFile).CopyHere(source_objects)
    Do While Count = ZipDest.Items().Count
    wScript.Sleep 200
    Loop





    share|improve this answer

































      1














      Here'a my attempt to summarize built-in capabilities windows for compression and uncompression - https://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f



      with a few given solutions that should work on almost every windows machine.



      As regards to the shell.application and WSH I preferred the jscript
      as it allows a hybrid batch/jscript file (with .bat extension) that not require temp files.I've put unzip and zip capabilities in one file plus a few more features.






      share|improve this answer

































        0














        If on Windows 8 or Windows Server 2012 you'll have PowerShell and .NET 4.5 so you can do this:



        zip.ps1 (usage: -directory <directory to zip up> -name <zip name>):



        param (
        [string]$directory,
        [string]$name
        )

        Add-Type -Assembly System.IO.Compression.FileSystem
        [System.IO.Compression.ZipFile]::CreateFromDirectory($directory, $name, [System.IO.Compression.CompressionLevel]::Optimal, $false)


        zip.bat (if you need a helper to call PowerShell for you, the directory is first argument and the zip name second):



        @Echo Off
        powershell -ExecutionPolicy ByPass -Command "& '%~dpn0.ps1' -directory '%1' -name '%2'"





        share|improve this answer

































          -5














          The Windows command line now provides the compact command which, as far as I can tell, is native to Windows. That should meet the requirements requested unless I missed something.






          share|improve this answer





















          • 8





            compact existed since XP and is a tool to manage NTFS compression

            – Der Hochstapler
            May 31 '13 at 20:06












          protected by Community Jun 1 '13 at 16:37



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?














          11 Answers
          11






          active

          oldest

          votes








          11 Answers
          11






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          83














          Here is an all batch file solution (a variation of my other answer) that will zip a file named c:ue_english.txt and put it in C:someArchive.zip:



          set FILETOZIP=c:ue_english.txt

          set TEMPDIR=C:temp738
          rmdir %TEMPDIR%
          mkdir %TEMPDIR%
          xcopy /s %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:someArchive.zip

          pause


          Write access is required to the parent of the folder stored in TEMPDIR. As this is often not the case for the root of drive C TEMPDIR may have to be changed.



          Write access is also required for the folder the .bat script is in (as it generates a file there).



          Also, please note that the file extension for the compressed file must be .zip. Attempts to use another extension may result in a script error. Instead, generate the .zip file and rename it.






          share|improve this answer





















          • 3





            @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

            – Aaron Bush
            Mar 2 '10 at 13:56













          • @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

            – Tom Wijsman
            Nov 29 '11 at 13:54













          • I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

            – erm3nda
            Dec 10 '13 at 6:59













          • Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

            – Nam G VU
            Oct 15 '14 at 2:11













          • @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

            – JohnG
            May 18 '16 at 16:21
















          83














          Here is an all batch file solution (a variation of my other answer) that will zip a file named c:ue_english.txt and put it in C:someArchive.zip:



          set FILETOZIP=c:ue_english.txt

          set TEMPDIR=C:temp738
          rmdir %TEMPDIR%
          mkdir %TEMPDIR%
          xcopy /s %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:someArchive.zip

          pause


          Write access is required to the parent of the folder stored in TEMPDIR. As this is often not the case for the root of drive C TEMPDIR may have to be changed.



          Write access is also required for the folder the .bat script is in (as it generates a file there).



          Also, please note that the file extension for the compressed file must be .zip. Attempts to use another extension may result in a script error. Instead, generate the .zip file and rename it.






          share|improve this answer





















          • 3





            @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

            – Aaron Bush
            Mar 2 '10 at 13:56













          • @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

            – Tom Wijsman
            Nov 29 '11 at 13:54













          • I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

            – erm3nda
            Dec 10 '13 at 6:59













          • Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

            – Nam G VU
            Oct 15 '14 at 2:11













          • @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

            – JohnG
            May 18 '16 at 16:21














          83












          83








          83







          Here is an all batch file solution (a variation of my other answer) that will zip a file named c:ue_english.txt and put it in C:someArchive.zip:



          set FILETOZIP=c:ue_english.txt

          set TEMPDIR=C:temp738
          rmdir %TEMPDIR%
          mkdir %TEMPDIR%
          xcopy /s %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:someArchive.zip

          pause


          Write access is required to the parent of the folder stored in TEMPDIR. As this is often not the case for the root of drive C TEMPDIR may have to be changed.



          Write access is also required for the folder the .bat script is in (as it generates a file there).



          Also, please note that the file extension for the compressed file must be .zip. Attempts to use another extension may result in a script error. Instead, generate the .zip file and rename it.






          share|improve this answer















          Here is an all batch file solution (a variation of my other answer) that will zip a file named c:ue_english.txt and put it in C:someArchive.zip:



          set FILETOZIP=c:ue_english.txt

          set TEMPDIR=C:temp738
          rmdir %TEMPDIR%
          mkdir %TEMPDIR%
          xcopy /s %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:someArchive.zip

          pause


          Write access is required to the parent of the folder stored in TEMPDIR. As this is often not the case for the root of drive C TEMPDIR may have to be changed.



          Write access is also required for the folder the .bat script is in (as it generates a file there).



          Also, please note that the file extension for the compressed file must be .zip. Attempts to use another extension may result in a script error. Instead, generate the .zip file and rename it.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 1 at 16:32









          Oreo

          1054




          1054










          answered Feb 22 '10 at 17:28









          Peter MortensenPeter Mortensen

          8,386166185




          8,386166185








          • 3





            @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

            – Aaron Bush
            Mar 2 '10 at 13:56













          • @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

            – Tom Wijsman
            Nov 29 '11 at 13:54













          • I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

            – erm3nda
            Dec 10 '13 at 6:59













          • Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

            – Nam G VU
            Oct 15 '14 at 2:11













          • @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

            – JohnG
            May 18 '16 at 16:21














          • 3





            @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

            – Aaron Bush
            Mar 2 '10 at 13:56













          • @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

            – Tom Wijsman
            Nov 29 '11 at 13:54













          • I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

            – erm3nda
            Dec 10 '13 at 6:59













          • Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

            – Nam G VU
            Oct 15 '14 at 2:11













          • @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

            – JohnG
            May 18 '16 at 16:21








          3




          3





          @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

          – Aaron Bush
          Mar 2 '10 at 13:56







          @quack I was holding out in the hope of some obscure command that I didn't know about. I can see how you might find that a difficult requirement if one doesn't exist, didn't mean to put anybody out.

          – Aaron Bush
          Mar 2 '10 at 13:56















          @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

          – Tom Wijsman
          Nov 29 '11 at 13:54







          @PeterMortensen: It may or may not be interesting to see how much this is simplified with Powershell. Here is a 5 line example, but there also exists a write-zip cmdlet that can be downloaded from the Pscx.

          – Tom Wijsman
          Nov 29 '11 at 13:54















          I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

          – erm3nda
          Dec 10 '13 at 6:59







          I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line... from the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. Sounds cool. "A zip from windows command line" is an old science fiction movie, right?

          – erm3nda
          Dec 10 '13 at 6:59















          Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

          – Nam G VU
          Oct 15 '14 at 2:11







          Why do we have to use a temp folder TEMPDIR? I think your intention is to wrap the file FILETOZIP by a folder right?

          – Nam G VU
          Oct 15 '14 at 2:11















          @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

          – JohnG
          May 18 '16 at 16:21





          @Peter Mortensen, I know this is an old thread, and this is almost what I'm looking for. Is there an option to compress one big file into smaller chunks?

          – JohnG
          May 18 '16 at 16:21













          37














          It is possible to zip files without installation of any additional
          software (I have tested it). The solution is:



          Run this in a command-line window to create a zip file
          named C:someArchive.zip containing all files in folder C:test3:



          CScript  zip.vbs  C:test3  C:someArchive.zip


          Where file zip.vbs contains:



          'Get command-line arguments.
          Set objArgs = WScript.Arguments
          Set FS = CreateObject("Scripting.FileSystemObject")
          InputFolder = FS.GetAbsolutePathName(objArgs(0))
          ZipFile = FS.GetAbsolutePathName(objArgs(1))

          'Create empty ZIP file.
          CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

          Set objShell = CreateObject("Shell.Application")

          Set source = objShell.NameSpace(InputFolder).Items

          objShell.NameSpace(ZipFile).CopyHere(source)

          'Required to let the zip command execute
          'If this script randomly fails or the zip file is not complete,
          'just increase to more than 2 seconds
          wScript.Sleep 2000


          I haven't tested it for paths and file names containing spaces. It may work if quotes
          are put around the command line parameters.





          How it works: the built-in zip functionality in Windows (Windows XP and later?) is
          exposed through COM interfaces from the Windows shell
          , explorer.exe - that is the "Shell.Application" part. This COM interface can be used from a VBScript script because
          such a script can access COM components. To make the script fully self-contained it creates
          an empty ZIP file to get started (one could also create an empty ZIP file and copy it to the target system along with the VBScript script).



          VBScript has been installed by default in every desktop
          release of Microsoft Windows since Windows 98.



          CScript.exe is part of Windows Script Host.
          Windows Script Host is distributed and installed by default on Windows 98 and later versions of Windows. It is also installed if Internet Explorer 5 (or a later version) is installed.






          share|improve this answer





















          • 1





            +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

            – Aaron Bush
            Feb 22 '10 at 13:30








          • 4





            @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

            – quack quixote
            Feb 22 '10 at 23:24













          • Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

            – Chuck Wilbur
            Jun 27 '12 at 21:08











          • Paths have to be absolute and it seems to randomly fail :(

            – kixorz
            Feb 13 '14 at 20:33











          • This should be selected as the answer.

            – The Duke Of Marshall שלום
            Mar 14 '14 at 17:48
















          37














          It is possible to zip files without installation of any additional
          software (I have tested it). The solution is:



          Run this in a command-line window to create a zip file
          named C:someArchive.zip containing all files in folder C:test3:



          CScript  zip.vbs  C:test3  C:someArchive.zip


          Where file zip.vbs contains:



          'Get command-line arguments.
          Set objArgs = WScript.Arguments
          Set FS = CreateObject("Scripting.FileSystemObject")
          InputFolder = FS.GetAbsolutePathName(objArgs(0))
          ZipFile = FS.GetAbsolutePathName(objArgs(1))

          'Create empty ZIP file.
          CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

          Set objShell = CreateObject("Shell.Application")

          Set source = objShell.NameSpace(InputFolder).Items

          objShell.NameSpace(ZipFile).CopyHere(source)

          'Required to let the zip command execute
          'If this script randomly fails or the zip file is not complete,
          'just increase to more than 2 seconds
          wScript.Sleep 2000


          I haven't tested it for paths and file names containing spaces. It may work if quotes
          are put around the command line parameters.





          How it works: the built-in zip functionality in Windows (Windows XP and later?) is
          exposed through COM interfaces from the Windows shell
          , explorer.exe - that is the "Shell.Application" part. This COM interface can be used from a VBScript script because
          such a script can access COM components. To make the script fully self-contained it creates
          an empty ZIP file to get started (one could also create an empty ZIP file and copy it to the target system along with the VBScript script).



          VBScript has been installed by default in every desktop
          release of Microsoft Windows since Windows 98.



          CScript.exe is part of Windows Script Host.
          Windows Script Host is distributed and installed by default on Windows 98 and later versions of Windows. It is also installed if Internet Explorer 5 (or a later version) is installed.






          share|improve this answer





















          • 1





            +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

            – Aaron Bush
            Feb 22 '10 at 13:30








          • 4





            @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

            – quack quixote
            Feb 22 '10 at 23:24













          • Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

            – Chuck Wilbur
            Jun 27 '12 at 21:08











          • Paths have to be absolute and it seems to randomly fail :(

            – kixorz
            Feb 13 '14 at 20:33











          • This should be selected as the answer.

            – The Duke Of Marshall שלום
            Mar 14 '14 at 17:48














          37












          37








          37







          It is possible to zip files without installation of any additional
          software (I have tested it). The solution is:



          Run this in a command-line window to create a zip file
          named C:someArchive.zip containing all files in folder C:test3:



          CScript  zip.vbs  C:test3  C:someArchive.zip


          Where file zip.vbs contains:



          'Get command-line arguments.
          Set objArgs = WScript.Arguments
          Set FS = CreateObject("Scripting.FileSystemObject")
          InputFolder = FS.GetAbsolutePathName(objArgs(0))
          ZipFile = FS.GetAbsolutePathName(objArgs(1))

          'Create empty ZIP file.
          CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

          Set objShell = CreateObject("Shell.Application")

          Set source = objShell.NameSpace(InputFolder).Items

          objShell.NameSpace(ZipFile).CopyHere(source)

          'Required to let the zip command execute
          'If this script randomly fails or the zip file is not complete,
          'just increase to more than 2 seconds
          wScript.Sleep 2000


          I haven't tested it for paths and file names containing spaces. It may work if quotes
          are put around the command line parameters.





          How it works: the built-in zip functionality in Windows (Windows XP and later?) is
          exposed through COM interfaces from the Windows shell
          , explorer.exe - that is the "Shell.Application" part. This COM interface can be used from a VBScript script because
          such a script can access COM components. To make the script fully self-contained it creates
          an empty ZIP file to get started (one could also create an empty ZIP file and copy it to the target system along with the VBScript script).



          VBScript has been installed by default in every desktop
          release of Microsoft Windows since Windows 98.



          CScript.exe is part of Windows Script Host.
          Windows Script Host is distributed and installed by default on Windows 98 and later versions of Windows. It is also installed if Internet Explorer 5 (or a later version) is installed.






          share|improve this answer















          It is possible to zip files without installation of any additional
          software (I have tested it). The solution is:



          Run this in a command-line window to create a zip file
          named C:someArchive.zip containing all files in folder C:test3:



          CScript  zip.vbs  C:test3  C:someArchive.zip


          Where file zip.vbs contains:



          'Get command-line arguments.
          Set objArgs = WScript.Arguments
          Set FS = CreateObject("Scripting.FileSystemObject")
          InputFolder = FS.GetAbsolutePathName(objArgs(0))
          ZipFile = FS.GetAbsolutePathName(objArgs(1))

          'Create empty ZIP file.
          CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

          Set objShell = CreateObject("Shell.Application")

          Set source = objShell.NameSpace(InputFolder).Items

          objShell.NameSpace(ZipFile).CopyHere(source)

          'Required to let the zip command execute
          'If this script randomly fails or the zip file is not complete,
          'just increase to more than 2 seconds
          wScript.Sleep 2000


          I haven't tested it for paths and file names containing spaces. It may work if quotes
          are put around the command line parameters.





          How it works: the built-in zip functionality in Windows (Windows XP and later?) is
          exposed through COM interfaces from the Windows shell
          , explorer.exe - that is the "Shell.Application" part. This COM interface can be used from a VBScript script because
          such a script can access COM components. To make the script fully self-contained it creates
          an empty ZIP file to get started (one could also create an empty ZIP file and copy it to the target system along with the VBScript script).



          VBScript has been installed by default in every desktop
          release of Microsoft Windows since Windows 98.



          CScript.exe is part of Windows Script Host.
          Windows Script Host is distributed and installed by default on Windows 98 and later versions of Windows. It is also installed if Internet Explorer 5 (or a later version) is installed.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 13 '17 at 13:24









          Patrick from NDepend team

          12016




          12016










          answered Feb 20 '10 at 15:48









          Peter MortensenPeter Mortensen

          8,386166185




          8,386166185








          • 1





            +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

            – Aaron Bush
            Feb 22 '10 at 13:30








          • 4





            @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

            – quack quixote
            Feb 22 '10 at 23:24













          • Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

            – Chuck Wilbur
            Jun 27 '12 at 21:08











          • Paths have to be absolute and it seems to randomly fail :(

            – kixorz
            Feb 13 '14 at 20:33











          • This should be selected as the answer.

            – The Duke Of Marshall שלום
            Mar 14 '14 at 17:48














          • 1





            +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

            – Aaron Bush
            Feb 22 '10 at 13:30








          • 4





            @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

            – quack quixote
            Feb 22 '10 at 23:24













          • Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

            – Chuck Wilbur
            Jun 27 '12 at 21:08











          • Paths have to be absolute and it seems to randomly fail :(

            – kixorz
            Feb 13 '14 at 20:33











          • This should be selected as the answer.

            – The Duke Of Marshall שלום
            Mar 14 '14 at 17:48








          1




          1





          +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

          – Aaron Bush
          Feb 22 '10 at 13:30







          +1 Good solution that will "Just Run", but I choose BAT for several other reasons not listed. So I would prefer a BAT solution.

          – Aaron Bush
          Feb 22 '10 at 13:30






          4




          4





          @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

          – quack quixote
          Feb 22 '10 at 23:24







          @Aaron Bush: this script and Beaner's both provide a command that zips a file on the commandline, using windows builtin functions, as requested. you can add that command to a batchfile like any other.

          – quack quixote
          Feb 22 '10 at 23:24















          Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

          – Chuck Wilbur
          Jun 27 '12 at 21:08





          Note that the paths passed in have to be absolute, not relative. I had to also use the techniques in the answer here: stackoverflow.com/q/1645843/99640

          – Chuck Wilbur
          Jun 27 '12 at 21:08













          Paths have to be absolute and it seems to randomly fail :(

          – kixorz
          Feb 13 '14 at 20:33





          Paths have to be absolute and it seems to randomly fail :(

          – kixorz
          Feb 13 '14 at 20:33













          This should be selected as the answer.

          – The Duke Of Marshall שלום
          Mar 14 '14 at 17:48





          This should be selected as the answer.

          – The Duke Of Marshall שלום
          Mar 14 '14 at 17:48











          12














          If you are open to using PowerShell, zip capabilities are available in .NET 2.0 (PowerShell is .NET). Here's an a example (source) credit to Mike Hodnick:



          ########################################################
          # out-zip.ps1
          #
          # Usage:
          # To zip up some files:
          # ls c:source*.txt | out-zip c:targetarchive.zip $_
          #
          # To zip up a folder:
          # gi c:source | out-zip c:targetarchive.zip $_
          ########################################################

          $path = $args[0]
          $files = $input

          if (-not $path.EndsWith('.zip')) {$path += '.zip'}

          if (-not (test-path $path)) {
          set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
          }

          $ZipFile = (new-object -com shell.application).NameSpace($path)
          $files | foreach {$zipfile.CopyHere($_.fullname)}





          share|improve this answer


























          • This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

            – Robert Schmidt
            Feb 25 '14 at 8:14








          • 2





            The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

            – Concrete Gannet
            Nov 24 '14 at 8:00
















          12














          If you are open to using PowerShell, zip capabilities are available in .NET 2.0 (PowerShell is .NET). Here's an a example (source) credit to Mike Hodnick:



          ########################################################
          # out-zip.ps1
          #
          # Usage:
          # To zip up some files:
          # ls c:source*.txt | out-zip c:targetarchive.zip $_
          #
          # To zip up a folder:
          # gi c:source | out-zip c:targetarchive.zip $_
          ########################################################

          $path = $args[0]
          $files = $input

          if (-not $path.EndsWith('.zip')) {$path += '.zip'}

          if (-not (test-path $path)) {
          set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
          }

          $ZipFile = (new-object -com shell.application).NameSpace($path)
          $files | foreach {$zipfile.CopyHere($_.fullname)}





          share|improve this answer


























          • This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

            – Robert Schmidt
            Feb 25 '14 at 8:14








          • 2





            The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

            – Concrete Gannet
            Nov 24 '14 at 8:00














          12












          12








          12







          If you are open to using PowerShell, zip capabilities are available in .NET 2.0 (PowerShell is .NET). Here's an a example (source) credit to Mike Hodnick:



          ########################################################
          # out-zip.ps1
          #
          # Usage:
          # To zip up some files:
          # ls c:source*.txt | out-zip c:targetarchive.zip $_
          #
          # To zip up a folder:
          # gi c:source | out-zip c:targetarchive.zip $_
          ########################################################

          $path = $args[0]
          $files = $input

          if (-not $path.EndsWith('.zip')) {$path += '.zip'}

          if (-not (test-path $path)) {
          set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
          }

          $ZipFile = (new-object -com shell.application).NameSpace($path)
          $files | foreach {$zipfile.CopyHere($_.fullname)}





          share|improve this answer















          If you are open to using PowerShell, zip capabilities are available in .NET 2.0 (PowerShell is .NET). Here's an a example (source) credit to Mike Hodnick:



          ########################################################
          # out-zip.ps1
          #
          # Usage:
          # To zip up some files:
          # ls c:source*.txt | out-zip c:targetarchive.zip $_
          #
          # To zip up a folder:
          # gi c:source | out-zip c:targetarchive.zip $_
          ########################################################

          $path = $args[0]
          $files = $input

          if (-not $path.EndsWith('.zip')) {$path += '.zip'}

          if (-not (test-path $path)) {
          set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
          }

          $ZipFile = (new-object -com shell.application).NameSpace($path)
          $files | foreach {$zipfile.CopyHere($_.fullname)}






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 16 '10 at 20:37









          Peter Mortensen

          8,386166185




          8,386166185










          answered Feb 19 '10 at 21:59









          BeanerBeaner

          3,02811415




          3,02811415













          • This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

            – Robert Schmidt
            Feb 25 '14 at 8:14








          • 2





            The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

            – Concrete Gannet
            Nov 24 '14 at 8:00



















          • This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

            – Robert Schmidt
            Feb 25 '14 at 8:14








          • 2





            The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

            – Concrete Gannet
            Nov 24 '14 at 8:00

















          This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

          – Robert Schmidt
          Feb 25 '14 at 8:14







          This is basically the same thing as the CScript code in other answers. No .NET features are used (and .NET doesn't have ZIP support anyway). I suspect this might also be sensitive to the timing issue.

          – Robert Schmidt
          Feb 25 '14 at 8:14






          2




          2





          The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

          – Concrete Gannet
          Nov 24 '14 at 8:00





          The .NET System.IO.Compression.ZipFile class was added in version 4.5 .

          – Concrete Gannet
          Nov 24 '14 at 8:00











          7














          You can eliminate the risk of timing out during compression by polling for existence of the compression dialog window. This method also handles the user cancelling out of the compression window.



          objShell.NameSpace(ZipFile).CopyHere(source)

          ' Wait for compression window to open
          set scriptShell = CreateObject("Wscript.Shell")
          Do While scriptShell.AppActivate("Compressing...") = FALSE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop

          ' Wait for compression to complete before exiting script
          Do While scriptShell.AppActivate("Compressing...") = TRUE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop





          share|improve this answer





















          • 1





            +1. Those code monkey-style ".Sleep(whatever)" make me sick.

            – ivan_pozdeev
            Jun 25 '13 at 14:30








          • 1





            If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

            – Wes
            Jun 27 '13 at 22:05
















          7














          You can eliminate the risk of timing out during compression by polling for existence of the compression dialog window. This method also handles the user cancelling out of the compression window.



          objShell.NameSpace(ZipFile).CopyHere(source)

          ' Wait for compression window to open
          set scriptShell = CreateObject("Wscript.Shell")
          Do While scriptShell.AppActivate("Compressing...") = FALSE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop

          ' Wait for compression to complete before exiting script
          Do While scriptShell.AppActivate("Compressing...") = TRUE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop





          share|improve this answer





















          • 1





            +1. Those code monkey-style ".Sleep(whatever)" make me sick.

            – ivan_pozdeev
            Jun 25 '13 at 14:30








          • 1





            If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

            – Wes
            Jun 27 '13 at 22:05














          7












          7








          7







          You can eliminate the risk of timing out during compression by polling for existence of the compression dialog window. This method also handles the user cancelling out of the compression window.



          objShell.NameSpace(ZipFile).CopyHere(source)

          ' Wait for compression window to open
          set scriptShell = CreateObject("Wscript.Shell")
          Do While scriptShell.AppActivate("Compressing...") = FALSE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop

          ' Wait for compression to complete before exiting script
          Do While scriptShell.AppActivate("Compressing...") = TRUE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop





          share|improve this answer















          You can eliminate the risk of timing out during compression by polling for existence of the compression dialog window. This method also handles the user cancelling out of the compression window.



          objShell.NameSpace(ZipFile).CopyHere(source)

          ' Wait for compression window to open
          set scriptShell = CreateObject("Wscript.Shell")
          Do While scriptShell.AppActivate("Compressing...") = FALSE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop

          ' Wait for compression to complete before exiting script
          Do While scriptShell.AppActivate("Compressing...") = TRUE
          WScript.Sleep 500 ' Arbitrary polling delay
          Loop






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '11 at 1:13









          sblair

          11.4k64068




          11.4k64068










          answered Nov 23 '11 at 0:47









          George YockeyGeorge Yockey

          7911




          7911








          • 1





            +1. Those code monkey-style ".Sleep(whatever)" make me sick.

            – ivan_pozdeev
            Jun 25 '13 at 14:30








          • 1





            If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

            – Wes
            Jun 27 '13 at 22:05














          • 1





            +1. Those code monkey-style ".Sleep(whatever)" make me sick.

            – ivan_pozdeev
            Jun 25 '13 at 14:30








          • 1





            If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

            – Wes
            Jun 27 '13 at 22:05








          1




          1





          +1. Those code monkey-style ".Sleep(whatever)" make me sick.

          – ivan_pozdeev
          Jun 25 '13 at 14:30







          +1. Those code monkey-style ".Sleep(whatever)" make me sick.

          – ivan_pozdeev
          Jun 25 '13 at 14:30






          1




          1





          If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

          – Wes
          Jun 27 '13 at 22:05





          If I am running a vbs with the above logic for waiting, how will this be handled if being launched via a scheduled task (where no user is physically logged in.)

          – Wes
          Jun 27 '13 at 22:05











          4














          If you are able to install the Resource Kit Tools, you will find a command line tool called COMPRESS that can create compressed archive files like zip.



          Microsoft (R) File Compression Utility  Version 5.00.2134.1
          Copyright (C) Microsoft Corp. 1990-1999. All rights reserved.

          Compresses one or more files.

          COMPRESS [-r] [-d] [-z] Source Destination
          COMPRESS -r [-d] [-z] Source [Destination]

          -r Rename compressed files.
          -d Update compressed files only if out of date.
          -zx LZX compression.
          -z MS-ZIP compression.
          -zq[n] Quantum compression and optional level
          (in range 1-7, default is 4).
          Source Source file specification. Wildcards may be used.
          Destination Destination file | path specification.
          Destination may be a directory.
          If Source is multiple files and -r is not specified,
          Destination must be a directory.





          share|improve this answer



















          • 2





            +1 Doesn't really solve things, but still good to know about.

            – Aaron Bush
            Feb 22 '10 at 13:28
















          4














          If you are able to install the Resource Kit Tools, you will find a command line tool called COMPRESS that can create compressed archive files like zip.



          Microsoft (R) File Compression Utility  Version 5.00.2134.1
          Copyright (C) Microsoft Corp. 1990-1999. All rights reserved.

          Compresses one or more files.

          COMPRESS [-r] [-d] [-z] Source Destination
          COMPRESS -r [-d] [-z] Source [Destination]

          -r Rename compressed files.
          -d Update compressed files only if out of date.
          -zx LZX compression.
          -z MS-ZIP compression.
          -zq[n] Quantum compression and optional level
          (in range 1-7, default is 4).
          Source Source file specification. Wildcards may be used.
          Destination Destination file | path specification.
          Destination may be a directory.
          If Source is multiple files and -r is not specified,
          Destination must be a directory.





          share|improve this answer



















          • 2





            +1 Doesn't really solve things, but still good to know about.

            – Aaron Bush
            Feb 22 '10 at 13:28














          4












          4








          4







          If you are able to install the Resource Kit Tools, you will find a command line tool called COMPRESS that can create compressed archive files like zip.



          Microsoft (R) File Compression Utility  Version 5.00.2134.1
          Copyright (C) Microsoft Corp. 1990-1999. All rights reserved.

          Compresses one or more files.

          COMPRESS [-r] [-d] [-z] Source Destination
          COMPRESS -r [-d] [-z] Source [Destination]

          -r Rename compressed files.
          -d Update compressed files only if out of date.
          -zx LZX compression.
          -z MS-ZIP compression.
          -zq[n] Quantum compression and optional level
          (in range 1-7, default is 4).
          Source Source file specification. Wildcards may be used.
          Destination Destination file | path specification.
          Destination may be a directory.
          If Source is multiple files and -r is not specified,
          Destination must be a directory.





          share|improve this answer













          If you are able to install the Resource Kit Tools, you will find a command line tool called COMPRESS that can create compressed archive files like zip.



          Microsoft (R) File Compression Utility  Version 5.00.2134.1
          Copyright (C) Microsoft Corp. 1990-1999. All rights reserved.

          Compresses one or more files.

          COMPRESS [-r] [-d] [-z] Source Destination
          COMPRESS -r [-d] [-z] Source [Destination]

          -r Rename compressed files.
          -d Update compressed files only if out of date.
          -zx LZX compression.
          -z MS-ZIP compression.
          -zq[n] Quantum compression and optional level
          (in range 1-7, default is 4).
          Source Source file specification. Wildcards may be used.
          Destination Destination file | path specification.
          Destination may be a directory.
          If Source is multiple files and -r is not specified,
          Destination must be a directory.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 19 '10 at 20:29









          cowgodcowgod

          1,55631323




          1,55631323








          • 2





            +1 Doesn't really solve things, but still good to know about.

            – Aaron Bush
            Feb 22 '10 at 13:28














          • 2





            +1 Doesn't really solve things, but still good to know about.

            – Aaron Bush
            Feb 22 '10 at 13:28








          2




          2





          +1 Doesn't really solve things, but still good to know about.

          – Aaron Bush
          Feb 22 '10 at 13:28





          +1 Doesn't really solve things, but still good to know about.

          – Aaron Bush
          Feb 22 '10 at 13:28











          3














          'Keep script waiting until compression is done
          Do Until objShell.NameSpace( ZipFile ).Items.Count = objShell.NameSpace( InputFolder ).Items.Count
          WScript.Sleep 200
          Loop





          share|improve this answer


























          • exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

            – Sonic Soul
            Apr 3 '14 at 21:25













          • For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

            – Thom Nichols
            Apr 27 '15 at 20:20
















          3














          'Keep script waiting until compression is done
          Do Until objShell.NameSpace( ZipFile ).Items.Count = objShell.NameSpace( InputFolder ).Items.Count
          WScript.Sleep 200
          Loop





          share|improve this answer


























          • exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

            – Sonic Soul
            Apr 3 '14 at 21:25













          • For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

            – Thom Nichols
            Apr 27 '15 at 20:20














          3












          3








          3







          'Keep script waiting until compression is done
          Do Until objShell.NameSpace( ZipFile ).Items.Count = objShell.NameSpace( InputFolder ).Items.Count
          WScript.Sleep 200
          Loop





          share|improve this answer















          'Keep script waiting until compression is done
          Do Until objShell.NameSpace( ZipFile ).Items.Count = objShell.NameSpace( InputFolder ).Items.Count
          WScript.Sleep 200
          Loop






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 7 '12 at 8:15









          Gnoupi

          7,67283556




          7,67283556










          answered Aug 7 '12 at 7:46









          Jiří KočaraJiří Kočara

          391




          391













          • exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

            – Sonic Soul
            Apr 3 '14 at 21:25













          • For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

            – Thom Nichols
            Apr 27 '15 at 20:20



















          • exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

            – Sonic Soul
            Apr 3 '14 at 21:25













          • For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

            – Thom Nichols
            Apr 27 '15 at 20:20

















          exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

          – Sonic Soul
          Apr 3 '14 at 21:25







          exactly what i was looking for.. but it does give me an error "missing on empty Zip file"

          – Sonic Soul
          Apr 3 '14 at 21:25















          For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

          – Thom Nichols
          Apr 27 '15 at 20:20





          For some reason this never increments, if I print objShell.NameSpace( ZipFile ).Items.Count inside the loop, it's always 0 even though the zip file is created and it has the expected contents inside...

          – Thom Nichols
          Apr 27 '15 at 20:20











          2














          Multiple files / directories with simplified code.



          cscript zip.vbs target.zip sourceFile1 sourceDir2 ... sourceObjN


          zip.vbs file



          Set objArgs = WScript.Arguments
          ZipFile = objArgs(0)

          ' Create empty ZIP file and open for adding
          CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
          Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

          ' Add all files/directories to the .zip file
          For i = 1 To objArgs.count-1
          zip.CopyHere(objArgs(i))
          WScript.Sleep 10000 'REQUIRED!! (Depending on file/dir size)
          Next





          share|improve this answer






























            2














            Multiple files / directories with simplified code.



            cscript zip.vbs target.zip sourceFile1 sourceDir2 ... sourceObjN


            zip.vbs file



            Set objArgs = WScript.Arguments
            ZipFile = objArgs(0)

            ' Create empty ZIP file and open for adding
            CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
            Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

            ' Add all files/directories to the .zip file
            For i = 1 To objArgs.count-1
            zip.CopyHere(objArgs(i))
            WScript.Sleep 10000 'REQUIRED!! (Depending on file/dir size)
            Next





            share|improve this answer




























              2












              2








              2







              Multiple files / directories with simplified code.



              cscript zip.vbs target.zip sourceFile1 sourceDir2 ... sourceObjN


              zip.vbs file



              Set objArgs = WScript.Arguments
              ZipFile = objArgs(0)

              ' Create empty ZIP file and open for adding
              CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
              Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

              ' Add all files/directories to the .zip file
              For i = 1 To objArgs.count-1
              zip.CopyHere(objArgs(i))
              WScript.Sleep 10000 'REQUIRED!! (Depending on file/dir size)
              Next





              share|improve this answer















              Multiple files / directories with simplified code.



              cscript zip.vbs target.zip sourceFile1 sourceDir2 ... sourceObjN


              zip.vbs file



              Set objArgs = WScript.Arguments
              ZipFile = objArgs(0)

              ' Create empty ZIP file and open for adding
              CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
              Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

              ' Add all files/directories to the .zip file
              For i = 1 To objArgs.count-1
              zip.CopyHere(objArgs(i))
              WScript.Sleep 10000 'REQUIRED!! (Depending on file/dir size)
              Next






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 5 '12 at 21:17

























              answered Nov 5 '12 at 21:06









              OlcOlc

              292




              292























                  2














                  This is a mutation of the accepted answer. I do a ton of automation tasks on up to thousands of files at a time, so I can't just sleep for 2 seconds and not care about it. I gleaned the workaround here, which is also similar to Jiří Kočara's answer here.



                  This will cause the destination folder to be pinged every 200ms, which is approximately as fast as Microsoft says to check for FS updates.



                  Set parameters = WScript.Arguments
                  Set FS = CreateObject("Scripting.FileSystemObject")
                  SourceDir = FS.GetAbsolutePathName(parameters(0))
                  ZipFile = FS.GetAbsolutePathName(parameters(1))
                  CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
                  Set shell = CreateObject("Shell.Application")
                  Set source_objects = shell.NameSpace(SourceDir).Items
                  Set ZipDest = shell.NameSpace(ZipFile)
                  Count=ZipDest.Items().Count
                  shell.NameSpace(ZipFile).CopyHere(source_objects)
                  Do While Count = ZipDest.Items().Count
                  wScript.Sleep 200
                  Loop





                  share|improve this answer






























                    2














                    This is a mutation of the accepted answer. I do a ton of automation tasks on up to thousands of files at a time, so I can't just sleep for 2 seconds and not care about it. I gleaned the workaround here, which is also similar to Jiří Kočara's answer here.



                    This will cause the destination folder to be pinged every 200ms, which is approximately as fast as Microsoft says to check for FS updates.



                    Set parameters = WScript.Arguments
                    Set FS = CreateObject("Scripting.FileSystemObject")
                    SourceDir = FS.GetAbsolutePathName(parameters(0))
                    ZipFile = FS.GetAbsolutePathName(parameters(1))
                    CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
                    Set shell = CreateObject("Shell.Application")
                    Set source_objects = shell.NameSpace(SourceDir).Items
                    Set ZipDest = shell.NameSpace(ZipFile)
                    Count=ZipDest.Items().Count
                    shell.NameSpace(ZipFile).CopyHere(source_objects)
                    Do While Count = ZipDest.Items().Count
                    wScript.Sleep 200
                    Loop





                    share|improve this answer




























                      2












                      2








                      2







                      This is a mutation of the accepted answer. I do a ton of automation tasks on up to thousands of files at a time, so I can't just sleep for 2 seconds and not care about it. I gleaned the workaround here, which is also similar to Jiří Kočara's answer here.



                      This will cause the destination folder to be pinged every 200ms, which is approximately as fast as Microsoft says to check for FS updates.



                      Set parameters = WScript.Arguments
                      Set FS = CreateObject("Scripting.FileSystemObject")
                      SourceDir = FS.GetAbsolutePathName(parameters(0))
                      ZipFile = FS.GetAbsolutePathName(parameters(1))
                      CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
                      Set shell = CreateObject("Shell.Application")
                      Set source_objects = shell.NameSpace(SourceDir).Items
                      Set ZipDest = shell.NameSpace(ZipFile)
                      Count=ZipDest.Items().Count
                      shell.NameSpace(ZipFile).CopyHere(source_objects)
                      Do While Count = ZipDest.Items().Count
                      wScript.Sleep 200
                      Loop





                      share|improve this answer















                      This is a mutation of the accepted answer. I do a ton of automation tasks on up to thousands of files at a time, so I can't just sleep for 2 seconds and not care about it. I gleaned the workaround here, which is also similar to Jiří Kočara's answer here.



                      This will cause the destination folder to be pinged every 200ms, which is approximately as fast as Microsoft says to check for FS updates.



                      Set parameters = WScript.Arguments
                      Set FS = CreateObject("Scripting.FileSystemObject")
                      SourceDir = FS.GetAbsolutePathName(parameters(0))
                      ZipFile = FS.GetAbsolutePathName(parameters(1))
                      CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
                      Set shell = CreateObject("Shell.Application")
                      Set source_objects = shell.NameSpace(SourceDir).Items
                      Set ZipDest = shell.NameSpace(ZipFile)
                      Count=ZipDest.Items().Count
                      shell.NameSpace(ZipFile).CopyHere(source_objects)
                      Do While Count = ZipDest.Items().Count
                      wScript.Sleep 200
                      Loop






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jun 10 '17 at 1:54

























                      answered Jun 7 '17 at 21:53









                      kayleeFrye_onDeckkayleeFrye_onDeck

                      1709




                      1709























                          1














                          Here'a my attempt to summarize built-in capabilities windows for compression and uncompression - https://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f



                          with a few given solutions that should work on almost every windows machine.



                          As regards to the shell.application and WSH I preferred the jscript
                          as it allows a hybrid batch/jscript file (with .bat extension) that not require temp files.I've put unzip and zip capabilities in one file plus a few more features.






                          share|improve this answer






























                            1














                            Here'a my attempt to summarize built-in capabilities windows for compression and uncompression - https://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f



                            with a few given solutions that should work on almost every windows machine.



                            As regards to the shell.application and WSH I preferred the jscript
                            as it allows a hybrid batch/jscript file (with .bat extension) that not require temp files.I've put unzip and zip capabilities in one file plus a few more features.






                            share|improve this answer




























                              1












                              1








                              1







                              Here'a my attempt to summarize built-in capabilities windows for compression and uncompression - https://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f



                              with a few given solutions that should work on almost every windows machine.



                              As regards to the shell.application and WSH I preferred the jscript
                              as it allows a hybrid batch/jscript file (with .bat extension) that not require temp files.I've put unzip and zip capabilities in one file plus a few more features.






                              share|improve this answer















                              Here'a my attempt to summarize built-in capabilities windows for compression and uncompression - https://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f



                              with a few given solutions that should work on almost every windows machine.



                              As regards to the shell.application and WSH I preferred the jscript
                              as it allows a hybrid batch/jscript file (with .bat extension) that not require temp files.I've put unzip and zip capabilities in one file plus a few more features.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited May 23 '17 at 11:33









                              Community

                              1




                              1










                              answered Jan 22 '15 at 12:31









                              npocmakanpocmaka

                              775710




                              775710























                                  0














                                  If on Windows 8 or Windows Server 2012 you'll have PowerShell and .NET 4.5 so you can do this:



                                  zip.ps1 (usage: -directory <directory to zip up> -name <zip name>):



                                  param (
                                  [string]$directory,
                                  [string]$name
                                  )

                                  Add-Type -Assembly System.IO.Compression.FileSystem
                                  [System.IO.Compression.ZipFile]::CreateFromDirectory($directory, $name, [System.IO.Compression.CompressionLevel]::Optimal, $false)


                                  zip.bat (if you need a helper to call PowerShell for you, the directory is first argument and the zip name second):



                                  @Echo Off
                                  powershell -ExecutionPolicy ByPass -Command "& '%~dpn0.ps1' -directory '%1' -name '%2'"





                                  share|improve this answer






























                                    0














                                    If on Windows 8 or Windows Server 2012 you'll have PowerShell and .NET 4.5 so you can do this:



                                    zip.ps1 (usage: -directory <directory to zip up> -name <zip name>):



                                    param (
                                    [string]$directory,
                                    [string]$name
                                    )

                                    Add-Type -Assembly System.IO.Compression.FileSystem
                                    [System.IO.Compression.ZipFile]::CreateFromDirectory($directory, $name, [System.IO.Compression.CompressionLevel]::Optimal, $false)


                                    zip.bat (if you need a helper to call PowerShell for you, the directory is first argument and the zip name second):



                                    @Echo Off
                                    powershell -ExecutionPolicy ByPass -Command "& '%~dpn0.ps1' -directory '%1' -name '%2'"





                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      If on Windows 8 or Windows Server 2012 you'll have PowerShell and .NET 4.5 so you can do this:



                                      zip.ps1 (usage: -directory <directory to zip up> -name <zip name>):



                                      param (
                                      [string]$directory,
                                      [string]$name
                                      )

                                      Add-Type -Assembly System.IO.Compression.FileSystem
                                      [System.IO.Compression.ZipFile]::CreateFromDirectory($directory, $name, [System.IO.Compression.CompressionLevel]::Optimal, $false)


                                      zip.bat (if you need a helper to call PowerShell for you, the directory is first argument and the zip name second):



                                      @Echo Off
                                      powershell -ExecutionPolicy ByPass -Command "& '%~dpn0.ps1' -directory '%1' -name '%2'"





                                      share|improve this answer















                                      If on Windows 8 or Windows Server 2012 you'll have PowerShell and .NET 4.5 so you can do this:



                                      zip.ps1 (usage: -directory <directory to zip up> -name <zip name>):



                                      param (
                                      [string]$directory,
                                      [string]$name
                                      )

                                      Add-Type -Assembly System.IO.Compression.FileSystem
                                      [System.IO.Compression.ZipFile]::CreateFromDirectory($directory, $name, [System.IO.Compression.CompressionLevel]::Optimal, $false)


                                      zip.bat (if you need a helper to call PowerShell for you, the directory is first argument and the zip name second):



                                      @Echo Off
                                      powershell -ExecutionPolicy ByPass -Command "& '%~dpn0.ps1' -directory '%1' -name '%2'"






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Jun 16 '17 at 15:53









                                      Peter Mortensen

                                      8,386166185




                                      8,386166185










                                      answered Aug 2 '16 at 11:19









                                      HashbrownHashbrown

                                      1,18922037




                                      1,18922037























                                          -5














                                          The Windows command line now provides the compact command which, as far as I can tell, is native to Windows. That should meet the requirements requested unless I missed something.






                                          share|improve this answer





















                                          • 8





                                            compact existed since XP and is a tool to manage NTFS compression

                                            – Der Hochstapler
                                            May 31 '13 at 20:06


















                                          -5














                                          The Windows command line now provides the compact command which, as far as I can tell, is native to Windows. That should meet the requirements requested unless I missed something.






                                          share|improve this answer





















                                          • 8





                                            compact existed since XP and is a tool to manage NTFS compression

                                            – Der Hochstapler
                                            May 31 '13 at 20:06
















                                          -5












                                          -5








                                          -5







                                          The Windows command line now provides the compact command which, as far as I can tell, is native to Windows. That should meet the requirements requested unless I missed something.






                                          share|improve this answer















                                          The Windows command line now provides the compact command which, as far as I can tell, is native to Windows. That should meet the requirements requested unless I missed something.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Jun 1 '13 at 21:34









                                          Peter Mortensen

                                          8,386166185




                                          8,386166185










                                          answered May 31 '13 at 19:54









                                          user228211user228211

                                          3




                                          3








                                          • 8





                                            compact existed since XP and is a tool to manage NTFS compression

                                            – Der Hochstapler
                                            May 31 '13 at 20:06
















                                          • 8





                                            compact existed since XP and is a tool to manage NTFS compression

                                            – Der Hochstapler
                                            May 31 '13 at 20:06










                                          8




                                          8





                                          compact existed since XP and is a tool to manage NTFS compression

                                          – Der Hochstapler
                                          May 31 '13 at 20:06







                                          compact existed since XP and is a tool to manage NTFS compression

                                          – Der Hochstapler
                                          May 31 '13 at 20:06







                                          protected by Community Jun 1 '13 at 16:37



                                          Thank you for your interest in this question.
                                          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                          Would you like to answer one of these unanswered questions instead?



                                          Popular posts from this blog

                                          Plaza Victoria

                                          In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                                          How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...