gpt4 book ai didi

vbscript - 如何在 vbscript 中解压缩受密码保护的文件?

转载 作者:行者123 更新时间:2023-12-04 05:04:46 25 4
gpt4 key购买 nike

我对 VBScript 相当陌生。我已经对我想要完成的事情进行了一些广泛的研究,甚至找到了要做什么的例子,但无法让它正常工作。

在我的完美世界中,我需要解压缩从第三方供应商发送到文件夹的所有压缩文件,将解压缩文件导入不同的文件夹,然后删除压缩文件。

下面的脚本适用于非密码保护的 zip 文件,但所有从供应商发送的文件都有密码。正如在另一个 post 中看到的,我注释掉的以下几行应该插入密码,但不要插入。 “...(pwd+myZipfile) ”和“...(pwd+extractTo) ”。

在此先感谢您的帮助。请提出任何代码改进或其他方法来实现这一点。

pathToZipFile = "P:\ZipFiles"  
extractTo = "P:\UnZip"
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(pathToZipFile)
Set fc = f.Files
Dim myZipFile
Dim intOptions, objShell, objSource, objTarget
Dim pwd
pwd = "password"

For Each f1 in fc
On Error Resume Next

myZipFile = f1

' Create the required Shell objects
Set objShell = CreateObject( "Shell.Application" )

' Create a reference to the files and folders
'Set objSource = objShell.NameSpace(pwd+myZipFile).Items( )
Set objSource = objShell.NameSpace(myZipFile).Items( )

' Create a reference to the target folder
Set objTarget = objShell.NameSpace(pwd+extractTo)
Set objTarget = objShell.NameSpace(extractTo)
intOptions = 256

' UnZIP the file
objTarget.CopyHere objSource, intOptions

' Release the objects
Set objSource = Nothing
Set objTarget = Nothing
Set objShell = Nothing

'Delete File from "P:\ZipFiles" after unzipping
fso.DeleteFile f1, True

Next

最佳答案

如果你仔细看看 answer从中pwd+...来了,你会注意到 pwd不包含密码,但包含路径。该变量可能以 Unix 命令 pwd 命名。 ,代表“打印工作目录”。

据我所知Shell.Application对象不支持解压受密码保护的 Zip 文件。 Another answer您引用的问题建议 DotNetZip library .或者你可以使用 7-zip :

Function qq(str)
qq = Chr(34) & str & Chr(34)
End Function

zipfile = "..."
password = "..."

Set sh = CreateObject("WScript.Shell")
sh.Run "7za.exe x " & qq(zipfile) & " -p" & qq(password), 0, True

关于vbscript - 如何在 vbscript 中解压缩受密码保护的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15666282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com