我们的构建过程会生成一堆.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