我們的構建過程會生成一堆.zip文件,例如ComponentA-1.2.3.4.zip
,其中1.2.3.4是內部版本號。該文件依次包含文件夾ComponentA-1.2.3.4
,該文件夾在文件夾結構中具有實際的工件。我正在編寫一個powershell腳本,它提取工件並將它們發送到服務器進行部署,並且需要將該結構放置在服務器上的頂層服務器之下。所以,假設這個結構:ComponentA-1.2.3.4.zip\ComponentA-1.2.3.4\{Web,Lib,Bin}
,我需要提取Web,Lib和Bin文件夾。從zip文件中的目錄複製文件
我複製使用這種方法的文件,此刻
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
我試圖操縱$zipPackage.Items()
對象,但獲取有關文件不exising錯誤。物體看起來像這樣在調試器:
>>> $ZipPackage.Items()
Application : System.__ComObject
Parent : System.__ComObject
Name : ComponentA-1.2.3.4
Path : D:\Release\1.2.3.4\ComponentA-1.2.3.4.zip\ComponentA-1.2.3.4
GetLink :
GetFolder : System.__ComObject
IsLink : False
IsFolder : True
IsFileSystem : False
IsBrowsable : False
ModifyDate : 2012-02-27 17:30:34
Size : 0
Type : File Folder
幾乎任何我不導致Cannot find path 'D:\release\1.2.3.4\System.__ComObject' because it does not exist
。
我想不必將文件提取到某個臨時位置只是走一步,但我不知道該怎麼做?
最後我打電話是7zip的:通過使用父拉鍊Objectto查詢zip文件中的根目錄的名稱,您可以半自動化此根路徑生成kB /秒)使用我上面嘗試的方法。 – carlpett 2012-03-13 09:06:21