2013-07-24 69 views
3

我有一個隨機文件名的zipfile,其中包含一個隨機命名的zipfile文件。我煉下面的示例代碼:powershell - 從zip中提取文件類型

$shell = new-object -com shell.application 
$zip = $shell.NameSpace(「C:\howtogeeksite.zip」) 
foreach($item in $zip.items()) 
{ 
$shell.Namespace(「C:\temp\howtogeek」).copyhere($item) 
} 

外的壓縮文件包含了幾百個文件,我不需要加內它 - 這一個zip文件如何提煉上面的源代碼,只搶到內zip文件(它可以從外部zip文件中提取擴展名爲.zip的所有文件)...請告知最簡單的方法。 謝謝!

+0

你必須知道名稱或名稱的模式,以識別它並提取它。你有這個名字或模式嗎? – Jimbo

回答

2

您需要在提取之前遍歷內容檢查每個項目的文件擴展名是否爲「.zip」。像這樣的東西應該工作:

$shell = new-object -com shell.application 
$zip = $shell.NameSpace(「C:\howtogeeksite.zip」) 

foreach($item in $zip.items()){ 

    if([System.IO.Path]::GetExtension($item.Path) -eq ".zip"){ 

     $shell.Namespace(「C:\temp\howtogeek」).copyhere($item) 

    } 

}