我想在PowerShell中创建一个zip文件,向其中添加项目,然后在同一脚本中立即以字节形式获取该zip文件的压缩内容。问题是似乎zip应用程序没有将其内容写入文件系统。如何关闭/刷新zip应用程序,以便下一个PowerShell语句可以访问新创建的zip文件?
示例:
示例:
new-item -type File test.zip -force
$zip = ( get-item test.zip ).fullname
$app = new-object -com shell.application
$folder = $app.namespace( $zip )
$item = new-item file.txt -itemtype file -value "Mooo" -force
$folder.copyhere( $item.fullname )
dir test.zip # <---- Empty test.zip file
Get-Content -Encoding byte $zip | echo # <-- nothing echoed
"dir test.zip" 显示一个没有内容的zip文件, 因此 Get-Content 返回了空。请注意,这似乎是 copyhere 操作异步行为的问题。如果我在 copyhere 行后睡眠,zip 文件将会被填充。然而,我不知道需要睡眠多长时间,也不想延迟处理。
非常感谢!
2 0 -1 -1 - Eric Vasilik