windowsvbscriptbatch-filezipscripting

Can Windows' built-in ZIP compression be scripted?


Is the ZIP compression that is built into Windows XP/Vista/2003/2008 able to be scripted at all? What executable would I have to call from a BAT/CMD file? or is it possible to do it with VBScript?

I realize that this is possible using WinZip, 7-Zip and other external applications, but I'm looking for something that requires no external applications to be installed.


Solution

  • If you've made it down to here, it's because nothing else has worked quite right for you, for one reason or another (just like me). I've done exhaustive research on this topic now, and using the Powershell option ending up being the best solution for me, mainly because it works with the Windows Shell Compress/Extract functionality. The following Powershell commands will work from the command line or inside of a batch file.

    Using Powershell 5.0 and higher, a command like the following will ZIP files and/or folders to a specific ZIP file path:

    // Zipping a file: 
    powershell Compress-Archive -Path 'C:\some_file.txt' -DestinationPath "zippedFile.zip"
    
    // Zipping a folder: 
    powershell Compress-Archive -Path 'C:\some_folder' -DestinationPath "zippedFolder.zip"
    
    // Zipping all files and folders within a directory, without the outer dir included in the ZIP file: 
    powershell Compress-Archive -Path 'C:\some_folder\*' -DestinationPath "zippedFolder.zip"
    

    Then to unzip the file to a specified folder path, you can use the following command:

    // Unzipping to a folder:
    powershell Expand-Archive -Path 'zippedFolder.zip' -DestinationPath 'C:\some_folder'
    

    This option will also work with all the ZIP utilities and functionality I've tried it on, but most importantly the Windows Compress and Extract options found on the context (right-click) menu in Windows Explorer.

    Also, I will say that there are many other threads similar to this thread with lots of options. So if you're still stuck after trying this, I might recommend looking other places too, such as:

    1. How can you zip or unzip from the script using ONLY Windows' built-in capabilities?

    2. How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools?

    3. https://superuser.com/questions/110991/can-you-zip-a-file-from-the-command-prompt-using-only-windows-built-in-capabili

    4. makecab - create a cab file from all the files in a folder