2014-11-20 33 views
1

我發現在線腳本,基本上解壓縮給定路徑中的每個.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

我設法自己做。基本上你想每次解壓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")