Lock Folder Up

I am trying to create a zip file in VBScript and it does not work. I am sure that I am creating the header file correctly.

It creates the actual file correctly, just does not fasten the folder.

Does anyone have any ideas:

Sub ArchiveFolder (folder) Dim fso, wShell, sApp, zipFile Set fso = CreateObject("Scripting.FileSystemObject") Set wShell = CreateObject("WScript.Shell") Set sApp = CreateObject("Shell.Application") Set zipFile = fso.CreateTextFile(folder & ".zip") ' Write zip file header. zipFile.Write "PK" & Chr(5) & Chr(6) & String(18, 0) zipFile.Close sApp.NameSpace(folder & ".zip").CopyHere folder End Sub 
+6
source share
3 answers

The answer I found here . The magic is in the last Do..Loop , where the script expects Shell to complete this task.

 ArchiveFolder "sub\foo.zip", "..\baz" Sub ArchiveFolder (zipFile, sFolder) With CreateObject("Scripting.FileSystemObject") zipFile = .GetAbsolutePathName(zipFile) sFolder = .GetAbsolutePathName(sFolder) With .CreateTextFile(zipFile, True) .Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, chr(0)) End With End With With CreateObject("Shell.Application") .NameSpace(zipFile).CopyHere .NameSpace(sFolder).Items Do Until .NameSpace(zipFile).Items.Count = _ .NameSpace(sFolder).Items.Count WScript.Sleep 1000 Loop End With End Sub 
+9
source

Check your argument. folder should be the path to the object you want to put in the zip file. If it is a folder object, you should use folder.Path , because the default method for folder objects is Name , and CopyHere cannot find the object with only the name.

You can add some debug statements to your function to verify that:

 WScript.Echo TypeName(folder) If fso.FolderExists(folder) Then WScript.Echo folder & " exists." Else WScript.Echo folder & " doesn't exist." End If 
+1
source

you can call an external zip file through% comspec%

oShell.Run "%comspec% /cc:\windows\7za.exe a " & oFile &".zip " & oFile & " -tzip",,True

Source http://www.scriptlook.com/zip-large-files-in-a-directory-2/

0
source

All Articles