【发布时间】:2015-07-04 15:25:12
【问题描述】:
我对 bash 或 vbs 知之甚少。我正在尝试制作一个脚本,它会自动解压缩一个名为“dungeon.zip”的 zip,其中包含我编写的一个小游戏。我想将它解压到一个名为 dungeon 的文件夹中,该文件夹位于 zip 文件所在的同一目录中。我使用了来自 this answer 的代码,并用我的文件替换了这些文件:
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
正如他的回答,我从 cmd 文件运行 .vbs:
cscript UnzipZip.vbs
这是错误:
C:\Users\Brett\Downloads\UnzipZip.vbs(12, 1) Microsoft VBScript runtime error: Object required: 'objShell.NameSpace(...)'
知道如何解决这个问题吗?
【问题讨论】:
-
您是否尝试过提供
dungeon.zip的完整路径?