简体   繁体   English

如何在同一文件夹中使用 powershell 生成 Zip

[英]How to generate the Zip using powershell with in same folder

Step1: need to zip below three files in same location with holds.zip Path: D:\Project\extensions\files inside this path having households filefolder xmldocument dll need to zip the file with these three files Step2:once zipped(holds.zip) delete the zip file and copy in D:\Project\extensions Step1: 需要zip 下面三个文件和holds.zip 路径:D:\Project\extensions\files 这个路径里面有户文件夹xmldocument dll 需要zip 这个文件和这三个文件Step2:一次压缩(holds.zip )删除zip文件,复制到D:\Project\extensions

using this command but not getting the required output Compress-Archive -Path D:\Project\extensions\files -DestinationPath D:\Project\extensions\files使用此命令但未获得所需的 output Compress-Archive -Path D:\Project\extensions\files -DestinationPath D:\Project\extensions\files

I tried re-creating the scenario you mentioned as follows:我尝试重新创建您提到的场景,如下所示:

Created a directory "D:\Project\extensions\files" that contains the following items:创建了一个包含以下项目的目录“D:\Project\extensions\files”:

  1. A File Folder named "datadocs"名为“datadocs”的文件夹
  2. An XML file named "script.xml"名为“script.xml”的 XML 文件
  3. A DLL file named "config.dll"名为“config.dll”的 DLL 文件

在此处输入图像描述

I executed the below PS script and it archived the folder contents in same location:我执行了以下 PS 脚本并将文件夹内容存档在同一位置:

$compress = @{
  Path = "D:\Project\extensions\files"
  CompressionLevel = "Fastest"
  DestinationPath = "D:\Project\extensions\files\holds.zip"
}
Compress-Archive @compress

在此处输入图像描述

Once the zip file was generated, I used the below cmdlet to delete it & move to "D:\Project\extensions" path:生成 zip 文件后,我使用以下 cmdlet 将其删除并移至“D:\Project\extensions”路径:

Move-Item "D:\Project\extensions\files\holds.zip" "D:\Project\extensions\holds.zip"

在此处输入图像描述

Hope this solution meets your requirements!希望这个解决方案能满足您的要求!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM