【发布时间】:2016-10-31 17:40:25
【问题描述】:
我们的构建过程会生成一堆 .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 文件夹。
我现在正在使用这种方法复制文件
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
我试图操纵$zipPackage.Items() 对象,但得到关于文件不存在的错误。该对象在调试器中如下所示:
>>> $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。
我不想为了走一步而将文件解压缩到某个临时位置,但我不明白该怎么做?
【问题讨论】:
标签: powershell zip