静默解压缩文件vbscript
问题描述:
我发现在线脚本,基本上解压缩给定路径中的每个.zip压缩文件。静默解压缩文件vbscript
sub UnzipAll(path)
set folder = fso.GetFolder(path)
for each file in folder.files
if (fso.GetExtensionName(file.path)) = "zip" then
set objShell = CreateObject("Shell.Application")
objshell.NameSpace(path).CopyHere objshell.NameSpace(file.path).Items
file.delete
end if
next
end sub
这实际上是工作,但问题是,我要解压缩“悄无声息”(默默意味着解压时,我不希望任何来自系统的消息,像“你想苏覆盖?“等)。
我搜索了很多关于谷歌和我发现,你只需要添加一些标志的“CopyHere”的方法,像这样:
objshell.NameSpace(path).CopyHere objshell.NameSpace(file.path).Items, *FLAGHERE*
但问题就在这里。这些标志通常会起作用,但是在解压缩.zip archieve时完全忽略它们。
所以我搜索了解决方法,但我没有找到任何有用的东西。
答
我设法自己做。基本上你想每次解压1个文件,而不是每个人都读取,在复制之前你只需检查它是否已经存在,然后删除即可:
set fso = CreateObject("Scripting.FileSystemObject")
sub estrai(percorso)
set cartella = fso.GetFolder(percorso)
for each file in cartella.files
if fso.GetExtensionName(file.path) = "zip" then
set objShell = CreateObject("Shell.Application")
set destinazione = objShell.NameSpace(percorso)
set zip_content = objShell.NameSpace(file.path).Items
for i = 0 to zip_content.count-1
'msgbox fso.Buildpath(percorso,zip_content.item(i).name)+"."+fso.getExtensionName(zip_content.item(i).path)
if (fso.FileExists(fso.Buildpath(percorso,zip_content.item(i).name)+"."+fso.getExtensionName(zip_content.item(i).path))) then
'msgbox "il file esiste, ora lo cancello"
fso.DeleteFile(fso.Buildpath(percorso,zip_content.item(i).name)+"."+fso.getExtensionName(zip_content.item(i).path))
end if
destinazione.copyHere(zip_content.item(i))
next
file.Delete
end if
next
'for each sottocartella in cartella.subfolders
' call estrai(folder.path)
'next
end sub
call estrai("C:\Documents and Settings\Mattia\Desktop\prova")