我想使用PowerShell脚本压缩目录。当我将压缩级别设置为Optimal或Fastest时,以下脚本可以工作,但它在SmallestSize中失败了。
$compressionLevel = [System.IO.Compression.CompressionLevel]::SmallestSize
[System.IO.Compression.ZipFile]::CreateFromDirectory("testfolder","D:Dev.zip", $compressionLevel, $false)
错误:
Cannot find an overload for "CreateFromDirectory" and the argument count: "4".
At line:1 char:1
+ [System.IO.Compression.ZipFile]::CreateFromDirectory("testfolder","D: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
如果我将压缩级别设置为最优/最快,则相同的脚本也能工作-$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
SmallestSize
不可用,如果PowerShell版本为5.1或更低,则其评估结果为null。
如果你想检查你有什么可用的选项,你可以运行以下命令:
[System.IO.Compression.CompressionLevel] | Get-Member -Static -MemberType Property