VBS解压缩 - 需要对象:'objshell.NameSpace(...)' [英] VBS unzipping - object required: 'objshell.NameSpace(...)'
问题描述
我对bash或vbs知之甚少。我试图做一个脚本,将自动解压缩一个名为dungeon.zip的zip,其中包含一个我编程的小游戏。我想将其解压到zip文件所在的目录中名为dungeon的文件夹中。我使用的代码来自 this answer < a>,并用我的文件替换文件:
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
.vbs从一个cmd文件:
As in his answer, I run the .vbs from a cmd file:
cscript UnzipZip.vbs
这是错误:
C:\Users\Brett\Downloads\UnzipZip.vbs(12, 1) Microsoft VBScript runtime error: Object required: 'objShell.NameSpace(...)'
有关如何解决此问题的任何建议吗?
Any idea on how to fix this?
推荐答案
WshShell.SpecialFolders(MyDocuments)
返回路径而不是尾部反斜杠。
WshShell.SpecialFolders("MyDocuments")
returns the path without a trailing backslash. You're then appending your filename to it.
您需要添加一个反斜杠。
You'll need to add a backslash.
strZipPath = strDesktop & "\" & strZipFile
strUnzipPath = strDesktop & "\" & strUnzipped
编辑以添加提示:
使用 BuildPath()
函数(它是 FileSystemObject
的一部分)
Use the BuildPath()
function (it's part of FileSystemObject
) to never have to worry about trailing backslashes again.
strZipPath = fso.BuildPath(strDesktop, strZipFile)
strUnzipPath = fso.BuildPath(strDesktop, strUnzipped)
这篇关于VBS解压缩 - 需要对象:'objshell.NameSpace(...)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!