如何使用 Windows XP 中的内部选项在 VBScript 中解压缩文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/911053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:25:08  来源:igfitidea点击:

How to unzip a file in VBScript using internal Windows XP options in

windowsscriptingvbscriptzip

提问by aviv

I want to unzip a .zip file using VBScript, only it's always a new computer with no external applications on it. Now I know Windows XP and 2003 have an internal .zip folder option, so I guess I can use it via VBScript in order to extract the file.

我想使用 VBScript 解压缩 .zip 文件,但它始终是一台没有外部应用程序的新计算机。现在我知道 Windows XP 和 2003 有一个内部 .zip 文件夹选项,所以我想我可以通过 VBScript 使用它来提取文件。

How do I do it?

我该怎么做?

I tried:

我试过:

Set objShell = CreateObject("Shell.Application")

Set SrcFldr = objShell.NameSpace(fileName)
Set DestFldr = objShell.NameSpace(appDir)
DestFldr.CopyHere(SrcFldr) 

Which didn't work. What could be the problem?

这没有用。可能是什么问题呢?

回答by Tester101

Just set ZipFile = The location of the zip file, and ExtractTo = to the location the zip file should be extracted to.

只需设置 ZipFile = zip 文件的位置,并将 ExtractTo = 设置为 zip 文件应解压缩到的位置。

'The location of the zip file.
ZipFile="C:\Test.Zip"
'The folder the contents should be extracted to.
ExtractTo="C:\Test\"

'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
   fso.CreateFolder(ExtractTo)
End If

'Extract the contants of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing