2013-04-11 155 views
1

以下腳本用於將zip壓縮到不同的文件夾並覆蓋現有文件。這個腳本在Windows 7機器上效果很好,但是當我在XP機器上使用這個腳本時,它仍然問是否要覆蓋。我需要與這個腳本沒有人際交互。任何幫助將不勝感激。謝謝。腳本適用於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 

回答

1

documentation說:

注意在某些情況下,如壓縮(.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 
相關問題