
Then I kick off the code which does the following. Thanks Nate, this is what I am trying to do….įirstly i manually extract my zip files to folder using 7zip on Win 8.1 (This is what I want to incorporate into my code). OShell.Run """" & s7zLocation & "7z.exe"" e -y -o""" & sLocation & """ """ & _Ĭategories Computers and Programming Post navigation If Not oFSO.FileExists(sArchiveName) Then '-Ensure we can find archive to uncompress. OShell.Run """" & s7zLocation & "7z.exe"" a -tzip -y """ & sArchiveName & """ " _ If oFSO.FileExists(sWorkingDirectory & "\" & "7z.exe") ThenĮlseIf oFSO.FileExists("C:\Program Files\7-Zip\7z.exe") Then SWorkingDirectory = Replace(Wscript.ScriptFullName, sScriptFilename, "") SScriptFilename = aScriptFileName(Ubound(aScriptFilename)) Set oShell = WScript.CreateObject("Wscript.Shell")ĪScriptFilename = Split(Wscript.ScriptFullName, "\") Set oFSO = WScript.CreateObject("Scripting.FileSystemObject") 'be used for commercial purposes with out the expressed written consent

'This script is provided under the Creative Commons license located

It will be created automatically by 7z.exe. When using the unzip function, if the folder you select to extract to doesn’t exist. You can pass as many files as you want using these methods. Be sure to include this any time you have a file that has spaces in it’s name or path. In the second example I used the double quotes because my path included spaces. Or you could specify the wild card character like this: sResults = Zip("""c:\program files\text files\*.txt""", "files.zip")

By calling each file in the local directory like this: sResults = Zip("file1.txt file2.txt file3.txt", "files.zip") If you want to use this script to compress more than one file at a time you can do this 2 distinct ways.

You can use these functions to compress or uncompress files or folders. Since 7Zip is such a handy tool I thought I’d whip up a script to utilize it’s command line version called 7z.exe so that I could call it from VBScript. I often use 7Zip for this task because it’s free and open source, has a great compression ratio, and supports a ton of formats. Occasionally it is really handy to zip and unzip files before you copy them around, or you want to archive them automatically for storage.
