0

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?

Community
  • 1
  • 1
KeithSmith
  • 774
  • 2
  • 8
  • 26
  • 1
    Possible duplicate of [Command line arguments - object required: 'objshell.NameSpace(...)'](http://stackoverflow.com/questions/12713740/command-line-arguments-object-required-objshell-namespace) –  Sep 12 '16 at 15:06

1 Answers1

1

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.

Community
  • 1
  • 1