【发布时间】:2019-03-15 01:52:54
【问题描述】:
我正在使用 vbscript 一个接一个地解压缩多个文件。
我正在使用下面的代码
Dim folder(3)
folder(0) = "UBO90R1"
folder(1) = "UBO90R2"
folder(2) = "UBO100R1"
folder(3) = "UBO100R2"
For i = 0 To 3
unzip_Source = "D:\Autobackup\" & folder(i) & ".zip"
unzip_destination = "D:\Autobackup_unzip\" & folder(i) &"\"
Call ExtractFilesFromZip(unzip_Source,unzip_destination)
WScript.Echo "unzip Finished"
Next
Sub ExtractFilesFromZip(pathToZipFile, dirToExtractFiles)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
pathToZipFile = fso.GetAbsolutePathName(pathToZipFile)
dirToExtractFiles = fso.GetAbsolutePathName(dirToExtractFiles)
If (Not fso.FileExists(pathToZipFile)) Then
WScript.Echo "Zip file does not exist: " & pathToZipFile
Exit Sub
End If
If Not fso.FolderExists(dirToExtractFiles) Then
WScript.Echo "Directory does not exist: " & dirToExtractFiles
Exit Sub
End If
dim sa : Set sa = CreateObject("Shell.Application")
Dim zip : Set zip = sa.NameSpace(pathToZipFile)
Dim d : Set d = sa.NameSpace(dirToExtractFiles)
d.CopyHere zip.items, 4
Do Until zip.Items.Count <= d.Items.Count
WScript.Sleep(200)
Loop
End Sub
目前我遇到的问题是,如果文件夹或文件已经存在,那么它会向用户打开对话框以选择任何选项覆盖、保留两个文件等。
如果我从代码中更改以下行
d.CopyHere zip.items, 4
'Integer 4 didn't show the progress bar
到
d.CopyHere zip.items, 16
'Integer 16 overwrite the existing file but it shows the progress bar.
我想在没有任何对话框和任何进度条的情况下覆盖现有文件。
PS:从here复制的解压代码。
【问题讨论】:
-
d.CopyHere zip.items, 4->d.CopyHere zip.items, 20 -
根据微软没有整数 20 (docs.microsoft.com/en-us/windows/desktop/api/shldisp/…)
-
来这里寻求帮助的人似乎总是认为他们比寻求帮助的人更了解什么有用或没用,这让我一直感到惊讶。你为什么不尝试一下,而不是成为一个无所不知的人?
-
20 = 16 和 4 = 4^2 + 2^2 = 在整数大小的标志中设置的第 4 位和第 2 位。
-
来这里寻求帮助的人似乎没有打开文档,这总是让我感到惊讶。
标签: windows vbscript scripting zip unzip