我遇到了write-zip的问题:第二次使用-Append参数调用Write-Zip时出现错误:额外的数据扩展Zip64信息长度无效。
我正在使用PSCX 2.1.x。
我通过创建一个函数来解决这个问题,该函数不是附加新文件,而是将现有的zip文件扩展到临时文件夹,将新文件添加到文件夹中,然后一次性压缩所有文件。 这有效......但效率不高。
有没有解决方案?
这是我的工作职能:
Function Add-To-Zip {
Param (
[Parameter(Mandatory=$True)]
[String] $Path,
[Parameter(Mandatory=$True)]
[String] $OutputPath,
[Parameter(Mandatory=$True)]
[String] $TempPath,
[Parameter(Mandatory=$False)]
[Boolean] $RemoveOriginal = $False
)
If (Test-Path $TempPath) {
Remove-Item -Path $TempPath -Recurse
}
New-Item -ItemType Directory -Path $TempPath
$paths = @()
Copy-Item $Path $TempPath
If (Test-Path $OutputPath) {
Expand-Archive -Path $OutputPath -OutputPath $TempPath
}
Get-ChildItem $TempPath | ForEach { $paths += Get-Item $_.FullName }
Try {
$paths | Write-Zip -OutputPath $OutputPath -Quiet -FlattenPaths -EntryPathRoot $TempPath
If ($RemoveOriginal) {
Remove-Item -Path $Path
}
} Catch {
Throw "An error occured while adding '$FilePath' to '$ZipPath'."
}
If (Test-Path $TempPath) {
Remove-Item -Path $TempPath -Recurse
}
}