【问题标题】:unzip file silently vbscript静默解压文件 vbscript
【发布时间】:2019-04-08 15:36:00
【问题描述】:

我发现在线脚本基本上可以解压缩给定路径中的每个 .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

这实际上是可行的,但问题是我想解压缩“静默”(静默意味着我在解压缩时不希望系统发出任何类型的消息,例如“do you想要覆盖吗?”等)。

我在google上搜索了很多,我发现你只需要在“CopyHere”方法上添加一些标志,就像这样:

objshell.NameSpace(path).CopyHere objshell.NameSpace(file.path).Items, *FLAGHERE*

但问题就在这里。这些标志通常会起作用,但在解压缩 .zip 存档时会完全忽略它们。

所以我搜索了一种解决方法,但没有发现任何有用的方法。

【问题讨论】:

    标签: vbscript unzip


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2010-10-29
      相关资源
      最近更新 更多