powershell - 如何使用 Powershell(压缩存档)在新文件夹中压缩存档?
问题描述
我需要在新文件夹中创建一个 zip 文件,但 powershellcompress-archive
destinationpath
不会强制创建文件夹。
我的目标在一个变量中。
$Composant = "foo.bar/foo.bar.ImportMe"
我的powershell代码是:
compress-archive -Path $outdirbuild/$Composant/* -DestinationPath "temp/OutilDeploiement/$($Composant).zip" -compressionlevel optimal -verbose
我的错误是:
Abandon : The path 'temp\OutilDeploiement\foo.bar' either does not exist or is not a valid file system path.
解决方案
这应该有效,如果没有,请告诉我:
$source = Join-Path $outdirbuild -ChildPath $Composant\*
$destination = 'absolutepath\to\zipfolder'
$fileName = 'zipfile.zip'
if(-not(Test-Path $destination))
{
New-Item -Path $destination -ItemType Directory -Force > $null
}
$params = @{
Path = $source
DestinationPath = Join-Path $destination -ChildPath $fileName
CompressionLevel = 'Optimal'
Verbose = $true
}
Compress-Archive @params
- 您可以在不确认的情况下添加
-Force
到压缩。 - 在源路径的末尾添加
\*
您没有压缩根文件夹,只是确认这是否是您想要的。
推荐阅读
- android - 如果我使用导航组件单击导航抽屉中的菜单,如何执行操作而不是移动到另一个目的地?
- java - 如何使键盘按键在每秒执行20次的方法中按下时执行一次方法?
- c# - 如何在 LightInject 中注册一个接受参数的开放泛型?
- session - 当第三方 cookie 被阻止时,YouTube 和 Gmail 如何共享登录会话
- google-app-engine - 如何在 GCP 的时间线上扩展批量计划任务?
- sql - Oracle - 查询不显示选择结果但插入记录
- opengl - 为什么我需要同时为 VBO 和调用 glVertexAttribPointer 指定数据?
- c# - C#:日期时间表单字符串
- python - 牛顿法梯度下降算法中的 TypeError 和 ValueError 回溯
- python - Anaconda 上的 opencv 与 PIP 上的 opencv-python 相同吗