【问题标题】:Using 7zip on powershell without compression在不压缩的 Powershell 上使用 7zip
【发布时间】:2014-02-24 12:58:51
【问题描述】:

我在 powershell 上使用 7zip,因为我需要压缩一些文件夹。这是我正在使用的代码:

Set-StrictMode -Version "2.0"
Clear-Host
$7Zip_ProgramPath="C:\Program Files\7-zip\7z"
$Destination = "c:\temp\7ztest41.zip"
$Source = "c:\temp\homes\homeuser002"
$Option = "a"
$Command = "$7Zip_ProgramPath $Option $Destination $Source"
#$Command="C:\Program Files\7-zip\7z a c:\temp\7ztest.zip c:\temp\homes\homeuser002"
$ManagementClass=[System.Management.ManagementClass] "\\.\ROOT\cimv2:Win32_Process"
#kürzer: $$ManagementClass=[WmiClass] "Win32_Process"
$StartupOptions=[WmiClass] "Win32_ProcessStartup"
$StartupOptions.PsBase.Properties["ShowWindow"].Value=1
$null=$ManagementClass.Create($Command,$Null,$StartupOptions)'

我从这个页面得到这个代码:http://www.powershellpraxis.de/index.php/ntfs-filesystem/laufwerke-ordner-dateien-und-freigaben#2.1.2.5.2%20Packen%20mit%207-Zip

一切都很好,除了我不想在使用这种方法时压缩我的文件。我有一个 67 MB 大的文件夹,但压缩此文件夹后只有 55 MB 大。也许我不完全理解这段代码,但我想更改压缩选项并且不知道在哪里以及如何。有人知道吗?

【问题讨论】:

    标签: powershell compression 7zip


    【解决方案1】:

    您的命令行仅指定“添加”操作。

    $Option = "a"
    

    “添加”选项不会禁用 7z.exe 中的压缩。您需要明确地configure the compression option 指定“不压缩”。

    $Option = 'a -mx=0'
    

    【讨论】:

    • 谢谢,这是我正在寻找的选项,但我找不到您所指的页面。我给你答案了。
    • 当我这样写时,7zip 不会启动。是否有其他形式的拼写?
    • 好的,我知道了。 $Option = 'a -mx=0 这对我来说非常好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    相关资源
    最近更新 更多