繁体   English   中英

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

[英]Powershell Compress-Archive files into folders

如何将结果放入存档的文件夹中? 例如:

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

我想在存档中有一个文件夹exe文件和一个服务器exe文件。 现在,所有文件都直接位于存档的“根目录”中。

压缩整个文件夹时,文件夹名称将包含在存档中。

这样的事情可能会让您从这里开始修改:-

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