【问题标题】:How to generate the Zip using powershell with in same folder如何在同一文件夹中使用 powershell 生成 Zip
【发布时间】:2020-09-01 16:42:23
【问题描述】:
Step1 : 需要使用hold.zip 将以下三个文件压缩到同一位置
路径:此路径内的 D:\Project\extensions\files
家庭文件夹
xml文档
dll需要用这三个文件压缩文件
Step2:一旦压缩(holds.zip)删除zip文件并复制到D:\Project\extensions
使用此命令但未获得所需的输出
Compress-Archive -Path D:\Project\extensions\files -DestinationPath D:\Project\extensions\files
【问题讨论】:
标签:
powershell
powershell-2.0
powershell-3.0
powershell-4.0
【解决方案1】:
我尝试重新创建您提到的场景如下:
创建了一个目录“D:\Project\extensions\files”,其中包含以下项目:
- 名为“datadocs”的文件夹
- 名为“script.xml”的 XML 文件
- 名为“config.dll”的 DLL 文件
我执行了以下 PS 脚本并将文件夹内容存档在同一位置:
$compress = @{
Path = "D:\Project\extensions\files"
CompressionLevel = "Fastest"
DestinationPath = "D:\Project\extensions\files\holds.zip"
}
Compress-Archive @compress
生成 zip 文件后,我使用以下 cmdlet 将其删除并移至“D:\Project\extensions”路径:
Move-Item "D:\Project\extensions\files\holds.zip" "D:\Project\extensions\holds.zip"
希望这个解决方案能满足您的要求!