我对VBScript相当陌生。我已经做了一些广泛的研究,我想要完成什么,甚至找到了一些例子,但不能让它正常工作。
在我理想的情况下,我需要解压缩从第三方供应商发送到一个文件夹的所有压缩文件,将解压缩的文件导入到另一个文件夹,然后删除压缩文件。
下面的脚本对于非密码保护的zip文件可以正常工作,但是从供应商发送的所有文件都有密码。正如在另一篇帖子中看到的,我注释掉的下面几行应该插入密码,但没有。"...(pwd+myZipfile)
"one_answers"...(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
如果您仔细查看pwd+...
来自的答案,您会注意到pwd
不包含密码,而是包含路径。该变量可能以Unix命令pwd
命名,代表"打印工作目录"。
据我所知,Shell.Application
对象不支持解包密码保护的Zip文件。您提到的问题的另一个答案建议使用DotNetZip库。或者你可以使用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