unsmip文件静默地vbscript

时间:2014-11-20 17:19:39

标签: 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")

        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 个答案:

答案 0 :(得分:2)

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