我正在处理JScript中的脚本,该脚本将从具有密码的ZIP存档中提取filez。首先,我在StackOverflow上的另一个线程上找到了VBS中的脚本,它可以解决问题,这里是:
WScript.echo("Instantiating a ZipFile object...")
Dim zip
Set zip = CreateObject("Ionic.Zip.ZipFile")
WScript.echo("Initialize (Read)...")
zip.Initialize("C:\Temp\ZipFile-created-from-VBScript.zip")
WScript.echo("setting the password for extraction...")
zip.Password = "This is the Password."
' set the default action for extracting an existing file
' 0 = throw exception
' 1 = overwrite silently
' 2 = don't overwrite (silently)
' 3 = invoke the ExtractProgress event
zip.ExtractExistingFile = 1
WScript.echo("extracting all files...")
Call zip.ExtractAll("extract")
WScript.echo("Disposing...")
zip.Dispose()
WScript.echo("Done.")
我试图用JScript重写此scipt,但是当我执行它时,它不断返回与Ionic.Zip.ZipFile
库相关的错误,因此我现在有了JScript的另一种解决方案:>
objShell = new ActiveXObject("Shell.Application");
FilesInZip = objShell.NameSpace(zipFile).Items();
objShell.NameSpace(path).copyHere(FilesInZip, 4);
但是,此脚本只是从存档中提取文件,有人可以查看这段代码并为我提供帮助,还是可以为我的问题寻求另一种解决方案?
答案 0 :(得分:1)
在最后一个示例中,您将无法使用密码从存档中提取文件,我建议您使用7zip或类似的名称。这是使用7zip进行取消存档的过程的一个示例:
function ExtractFile(FileName, Password) {
executableCommand = "x " + FileName + " -p" + Password;
objShell.ShellExecute("7z.exe", executableCommand, /*Path to 7Zip*/, "open", 0);
}