0

I know very little about bash or vbs. I am trying to make a script that will automatically unzip a zip called 'dungeon.zip', which contains a little game I programmed. I want to unzip it to a folder called dungeon in the same directory that the zip file was in. I used the code from this answer, and replaced the files with my files:

strZipFile  = "dungeon.zip"
strUnzipped = "dungeon\"

Sub UnZip(ExtractTo,ZipFile)

Set fso = CreateObject("Scripting.FileSystemObject") 
    If NOT fso.FolderExists(ExtractTo) Then 
       fso.CreateFolder(ExtractTo) 
End If 

Set objShell = CreateObject("Shell.Application") 
Set FilesInZip=objShell.NameSpace(ZipFile).items 

ObjShell.NameSpace(ExtractTo).CopyHere(FilesInZip) 
Set fso = Nothing 
Set objShell = Nothing 
End Sub

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("MyDocuments")

strZipPath   = strDesktop & strZipFile
strUnzipPath = strDesktop & strUnzipped

UnZip strUnzipPath , strZipPath

As in his answer, I run the .vbs from a cmd file:

cscript UnzipZip.vbs

Here is the error:

C:\Users\Brett\Downloads\UnzipZip.vbs(12, 1) Microsoft VBScript runtime error: Object required: 'objShell.NameSpace(...)'

Any idea on how to fix this?

1
  • In the original script the strZipFile and strUnzipped folder both use a relative path starting with "\". Is there a specific reason why you omitted that? You probably either need to put your script in the same folder als the zipfile and add that or use the fullpath
    – Syberdoor
    Jul 6, 2015 at 7:41

1 Answer 1

0

strDesktop returns a string without a trailing "\". So strDesktop & strZipFile will return a string for a path that does not exist.

For both concatenations, insert & "\" (e.g. strDesktop & "\" & strZipFile). As far as I know, double "\" will evaluate to a single "\" in paths, at least in some VB dialects.

I also note that you don't test for file existence before you attempt to unzip it (which is really what the error you get refers to), and that strDesktop is asigned the value of "MyDocuments" (not an error, more like "set duck=horse")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .