以下脚本用于将zip解压缩到其他文件夹并覆盖现有文件。这个脚本在Windows 7机器上运行良好,但是当我在XP机器上使用它时,它仍然会询问我是否要覆盖它。我需要与此脚本没有人工交互。任何帮助将不胜感激。谢谢。
strZipFile = "Location.zip" 'name of zip file
outFolder = "Location output folder" 'destination folder of unzipped files
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 4 + 16 + 1024
objTarget.CopyHere objSource, intOptions
答案 0 :(得分:1)
注意在某些情况下,例如压缩(.zip)文件,设计可能会忽略某些选项标记。
在WinXP上似乎就是这种情况,因此当您想强制替换现有文件时,必须使用不同的方法。例如,您可以将文件解压缩到临时文件夹,然后将它们复制到实际目的地:
Set fso = CreateObject("Scripting.FileSystemObject")
'create temporary folder with random name
Randomize
tempFolder = fso.BuildPath(fso.GetSpecialFolder(2), Fix(Rnd * 100000))
fso.CreateFolder tempFolder
strZipFile = "Location.zip" 'name of zip file
outFolder = "Location output folder" 'destination folder of unzipped files
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items
Set objTarget = objShell.NameSpace(tempFolder)
objTarget.CopyHere objSource
fso.CopyFolder tempFolder, outFolder, True
fso.DeleteFolder tempFolder, True 'delete temporary folder