以静默方式解压缩文件VBcript



我发现在线脚本基本上解压缩给定路径中的每个.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")
        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存档时会完全忽略它们。

所以我寻找解决方法,但没有找到任何有用的东西。

我设法自己做到了。基本上你想每次解压缩 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 SettingsMattiaDesktopprova")

最新更新