本文介绍了VBS解压缩 - 需要对象:'objshell.NameSpace(...)'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我对bash或vbs知之甚少。我试图做一个脚本,将自动解压缩一个名为dungeon.zip的zip,其中包含一个我编程的小游戏。我想将其解压到zip文件所在的目录中名为dungeon的文件夹中。我使用的代码来自 this answer ,并用我的文件替换文件: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 IfSet objShell = CreateObject("Shell.Application")Set FilesInZip=objShell.NameSpace(ZipFile).itemsObjShell.NameSpace(ExtractTo).CopyHere(FilesInZip)Set fso = NothingSet objShell = NothingEnd Subset WshShell = WScript.CreateObject("WScript.Shell")strDesktop = WshShell.SpecialFolders("MyDocuments")strZipPath = strDesktop & strZipFilestrUnzipPath = strDesktop & strUnzippedUnZip 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 & "\" & strZipFilestrUnzipPath = 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(...)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-04 18:22