在vbscript中以静默方式解压缩文件
我发现了一个在线脚本,它基本上可以将每个.zip归档文件解压到给定的路径中在vbscript中以静默方式解压缩文件,vbscript,unzip,Vbscript,Unzip,我发现了一个在线脚本,它基本上可以将每个.zip归档文件解压到给定的路径中 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") objshe
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
这实际上是可行的,但问题是我想“静默地”解压(静默意味着解压时我不想从系统收到任何类型的消息,如“是否要覆盖?”等)
我在google上搜索了很多,发现您只需在“CopyHere”方法上添加几个标志,如下所示:
objshell.NameSpace(path).CopyHere objshell.NameSpace(file.path).Items, *FLAGHERE*
但问题就在这里。这些标志通常会起作用,但在解压缩.zip存档文件时会完全忽略它们
所以我寻找了一个解决方法,但没有找到任何有用的方法。我自己设法做到了。基本上,您希望每次解压缩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")