简体   繁体   English

Powershell将压缩文件压缩到文件夹中

[英]Powershell Compress-Archive files into folders

How can I place the result into folders in the archive? 如何将结果放入存档的文件夹中? for example: 例如:

$Compress-Archive -Path .\Client\*.exe, .\Server\*.exe  -DestinationPath ('Build_' + (get-date -Format yyyy.MM.dd) + '.zip')

I would like to have a folder Client with it's exe files and a folder Server with it's exe files in the archive. 我想在存档中有一个文件夹exe文件和一个服务器exe文件。 Now all files are directly in the 'root' of the archive. 现在,所有文件都直接位于存档的“根目录”中。

When compressing an entire folder the folder name is included in the archive. 压缩整个文件夹时,文件夹名称将包含在存档中。

Something like this may get you started modified from here :- 这样的事情可能会让您从这里开始修改:-

https://social.technet.microsoft.com/Forums/en-US/fb835e63-0ed5-417b-980b-46d2982f4e0b/add-a-folder-to-an-existing-zip-file-using-powershell-v4-or-lower?forum=winserverpowershell https://social.technet.microsoft.com/Forums/zh-CN/fb835e63-0ed5-417b-980b-46d2982f4e0b/add-a-folder-to-an-existing-zip-file-using-powershell-v4-或更低?forum = winserverpowershell

$sources = "c:\client","c:\server"
$destination = "c:\test\" + "multifoler.zip"

function Add-Zip
   {
    param([string]$zipfilename)

    if(-not (test-path($zipfilename)))
    {
        set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
        (dir $zipfilename).IsReadOnly = $false  
}

$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)

foreach($file in $input) 
{ 
        $zipPackage.CopyHere($file.FullName)
        Start-sleep -milliseconds 500
}
}

foreach($source in $sources){
 Get-Item $source | Add-Zip $destination
}

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

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