aejas.blogg.se

Creating a zip file in microsoft 2010
Creating a zip file in microsoft 2010










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).

creating a zip file in microsoft 2010

This COM interface can be used from a VBScript script because such a script can access COM components. 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. It may work if quotesĪre put around the command line parameters. I haven't tested it for paths and file names containing spaces. ' If this script randomly fails or the ZIP file is not complete, ' Required to let the ZIP command execute ObjShell.NameSpace(ZipFile).CopyHere(source) Set source = objShell.NameSpace(InputFolder).Items Set objShell = CreateObject("Shell.Application") ZipFile = FS.GetAbsolutePathName(objArgs(1))ĬreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar) InputFolder = FS.GetAbsolutePathName(objArgs(0)) Set FS = CreateObject("Scripting.FileSystemObject") Where file zip.vbs contains: ' Get command-line arguments. Named C:\someArchive.zip containing all files in folder C:\test3: CScript zip.vbs C:\test3 C:\someArchive.zip Run this in a command-line window to create a ZIP file

creating a zip file in microsoft 2010

It is possible to zip files without installation of any additional software (I have tested it). Attempts to use another extension may result in a script error. bat script is in (as it generates a file there).Īlso, please note that the file extension for the compressed file must be.

creating a zip file in microsoft 2010

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

creating a zip file in microsoft 2010

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Įcho Set objArgs = WScript.Arguments > _zipIt.vbsĮcho InputFolder = objArgs(0) > _zipIt.vbsĮcho CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) > _zipIt.vbsĮcho Set objShell = CreateObject("Shell.Application") > _zipIt.vbsĮcho Set source = objShell.NameSpace(InputFolder).Items > _zipIt.vbsĮcho objShell.NameSpace(ZipFile).CopyHere(source) > _zipIt.vbsĬScript _zipIt.vbs %TEMPDIR% C:\someArchive.zip












Creating a zip file in microsoft 2010