Powershell压缩 - 将文件存档到文件夹中

时间:2018-04-26 14:28:28

标签: powershell compression

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

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

我想要一个文件夹Client包含它的exe文件,文件夹Server包含它的exe文件。现在所有文件都直接位于存档的“根”中。

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

1 个答案:

答案 0 :(得分:0)

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

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

$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
}
相关问题