Multi Commander > Script

7-zip profiles vs cmd line 7-zip?

(1/2) > >>

Ulfhednar:
I was looking at using a script that calls the packer function & uses 7-zip max compression, but cannot see how to specify or change the command for MAX on 7-zip specifically in the packer profiles, I cannot get the 'external' button to work for an external packer either. Duh not activated yet :-\  ;D
Running Internal zip (MAX) doesn't give me the smallest possible output.
Is this functionality present or do I just call the external 7-zip?

I got as far as this, where I wanted to compress selected subfolders:-

--- Quote ---@var $zipPath = "C:\Program Files\7-Zip\7z.exe";
@var $scanDir = "C:\path\to\the\directory";

@function CompressFolder($folderPath, $folderName) {
    @var $zipFileName = "$folderName.7z";
    MC.Run CMD="EXTRACT" TARGET="$folderPath" SOURCE="\"$zipFileName\"" USERCONFIRMATION="NO" ARCHIVE="$zipPath" ARGUMENTS="a -r \"$zipFileName\" \"$folderPath\\*\"";
}

@function ScanFolders($currentDir) {
    @var $dirs = MC.Filesystem.ListDirs(path="$currentDir");
    @for $dir in $dirs {
        @var $folderName = MC.GetValue(PATH="$dir", INDEX="basename");
        @if ($folderName == "a" || $folderName == "b") {
            CompressFolder($dir, $folderName);
        }
        ScanFolders($dir);
    }
}

ScanFolders($scanDir);

--- End quote ---

Any help on how to call max compression appreciated ;)

Mathias (Author):
Currently MC is using the default value when compressing using 7Zip.. It is on the list to allow for modifying them. I just pushed that forward since building a UI for that is boring.

I will se If I get the time to put some time to it. It been high on the list for a while.

If you use the cmd line exe I think the compression level is -mx9 for maximum.
but there are other related setting to for it that affect compression

https://documentation.help/7-Zip/method.htm (make sure you scroll down to 7z.. )

Ulfhednar:
Thanks for the reply Mathias.
I will try to run it with the CLI values & see how far I get ;)
-mx9 is the max 7-Zip compression switch.

Ulfhednar:
I ended up adding a Console .bat to a button.
This works OK scanning for subfolders, 7-zipping at max compression & deleting if 7z op is OK. Ops are logged to txt on base dir.

I would like to be able to do sth like this with MS as I think I could potentially make a richer & more functionally extensive script but I'm not sharp enough on MS atm  :-\
I will see if I can come up with sth in due course ;)


--- Code: ---@echo off
setlocal

REM Set the base directory
set "base_dir=C:\dir\to\scan\"
REM Set the full path to the 7-zip executable
set "7zip_path=C:\Program Files\7-Zip\7z.exe"
REM Set the log file path
set "log_file=%base_dir%\operations_log.txt"

REM Initialize the log file
echo Log file created on %date% at %time% > "%log_file%"

REM Recursively scan for folders named "a" and "b"
for /d /r "%base_dir%" %%d in (.) do (
    if exist "%%d\a" (
        echo Compressing folder "a" in "%%d" >> "%log_file%"
        "C:\Program Files\7-Zip\7z.exe" a -t7z -mx=9 "%%d\a.7z" "%%d\a\" >> "%log_file%" 2>&1
        if exist "%%d\a.7z" (
            echo Zip succeeded. Deleting folder "%%d\a" >> "%log_file%"
            rmdir /s /q "%%d\a" >> "%log_file%" 2>&1
        ) else (
            echo Failed to create zip for "%%d\a" >> "%log_file%"
        )
    )

    if exist "%%d\b" (
        echo Compressing folder "b" in "%%d" >> "%log_file%"
        "C:\Program Files\7-Zip\7z.exe" a -t7z -mx=9 "%%d\b.7z" "%%d\b\" >> "%log_file%" 2>&1
        if exist "%%d\b.7z" (
            echo Zip succeeded. Deleting folder "%%d\b" >> "%log_file%"
            rmdir /s /q "%%d\b" >> "%log_file%" 2>&1
        ) else (
            echo Failed to create zip for "%%d\b" >> "%log_file%"
        )
    )
)

endlocal
--- End code ---

Mathias (Author):
Not sure I understand what you ar doing.. packing each file in a folder and subfolders into its own 7z archive ?

Navigation

[0] Message Index

[#] Next page

Go to full version