KeithSmith
KeithSmith

Reputation: 774

Clarification of VB Script Program to Zip Files Error Message

Below is a small VB script that I believe should zip files in a folder. I am new to VB script.

Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
ZipFile = objArgs(1)
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)
wScript.Sleep 2000

I found the script here. Batch file script to zip files

I run the script with the following

CScript zipt.vbs ..\AFolder AFolder.zip

I get the following error:

zipIt.vbs(6, 1) Microsoft VBScript runtime error: Object required
: 'objShell.NameSpace(...)'

..\AFolder is not empty. The zip file is created and is empty.

Debugging the script, the error is on this line.

Set source = objShell.NameSpace(InputFolder).Items

What does the error message mean?

Upvotes: 0

Views: 443

Answers (1)

user736893
user736893

Reputation:

Based on this question, try this:

Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
InputFolder = fso.GetAbsolutePathName(WScript.Arguments.Item(0))
ZipFile = fso.GetAbsolutePathName(objArgs(1))
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)
wScript.Sleep 2000

To clarify, the script essentially didn't know what "AFolder.zip" was so it needs the entire, absolute path.

Upvotes: 1

Related Questions