Multi Commander Support Forum
Multi Commander => Script => Topic started by: Ulfhednar on February 07, 2025, 15:57:14
-
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:-
@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);
Any help on how to call max compression appreciated ;)
-
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.. )
-
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.
-
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 ;)
@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
-
Not sure I understand what you ar doing.. packing each file in a folder and subfolders into its own 7z archive ?
-
Yes the idea was to scan subfolders; zip specifically named folders; delete those source zipped folders, leaving the 7z in their place & log operations.
(a & b were just placeholders for my test before giving it actual pathing)
I was thinking of adding a StrIsRegExpMatchNoCase or similar to delete redundant files recursively. Basically a tidy up operation on a number of subfolders.
I got this, but the DeleteFiles instruction hangs the debugger & MC with a deletion dialog, tried with & without {}s on the last instruction. Also tried SILENT to no effect ???
Am I missing sth or is this a bug?
@var $currentPath = GetSourcePath();
@var $Items = GetSourceItems();
@var $count = arrayCount($Items);
@var $curItem;
@var $fullFilename;
@var $array2[];
// Loop all items in the $Items array
for( $n = 0; $n < $count; $n++)
{
$curItem = $Items[$n];
$fullFilename = $currentPath ^ $curItem;
@var $isMatch = StrIsRegExpMatchNoCase($fullFilename, "[a-z0-9]{30}");
if($isMatch)
{
arrayAdd($array2, $curItem);
}
}
@var $options[] = {"NODIALOG"};
DeleteFiles($array2, $options);
Thanks in advance for looking at this
-
Yes the idea was to scan subfolders; zip specifically named folders; delete those source zipped folders, leaving the 7z in their place & log operations.
(a & b were just placeholders for my test before giving it actual pathing)
I was thinking of adding a StrIsRegExpMatchNoCase or similar to delete redundant files recursively. Basically a tidy up operation on a number of subfolders.
I got this, but the DeleteFiles instruction hangs the debugger & MC with a deletion dialog, tried with & without {}s on the last instruction. Also tried SILENT to no effect ???
Am I missing sth or is this a bug?
@var $currentPath = GetSourcePath();
@var $Items = GetSourceItems();
@var $count = arrayCount($Items);
@var $curItem;
@var $fullFilename;
@var $array2[];
// Loop all items in the $Items array
for( $n = 0; $n < $count; $n++)
{
$curItem = $Items[$n];
$fullFilename = $currentPath ^ $curItem;
@var $isMatch = StrIsRegExpMatchNoCase($fullFilename, "[a-z0-9]{30}");
if($isMatch)
{
arrayAdd($array2, $curItem);
}
}
@var $options[] = {"NODIALOG"};
DeleteFiles($array2, $options);
Thanks in advance for looking at this
Hang the debugger ? hmm any error dialog that popup behind MC maybe ?
this work for me
@var $deleteOptions[] = {"NODIALOG"};
@var $files[] = {"R:\\Target\\File.zip", "R:\\Target\\File1.zip", "R:\\Target\\File2.zip"};
DeleteFiles($files, $deleteOptions);
-
Thanks for the reply Mathias.
Using your code works i.e. giving the instruction a fixed path for items, when I try to get it to work calling the items in my filtered array, it hangs.
The debugger has the red highlight active on the last line but clicking on anything fails to advance the operation.
The only window that shouldn't be present is the hung dialog. (See attached) No error dialogs or windows.
All MC dialogs will minimize but won't finish the op, restart req'd.
Is it related to how the path/filename is being added to the array? the $fullfilename is correctly enumerated in the debugger showing the whole string.
-
Not sure why i hangs for you. it is strange.. all file operations are handled in background threads.
Can you give me a script that fails and a list how with how the the file structure should be for the script. Then I can test using the same file structure as you.. if it is something with the files or script
-
Sorry for destroying your Monday morning Mathias.
You pointed me in the right direction.
So I realized what was wrong finally!
I'd used
@var $Items = GetSourceItems();
but should have used
@var $Items = GetSourceItems(1);
::)
Thanks for the assist :)
A bit OT:-
https://multicommander.com/Docs/multiscript/functions/filesystem#deletefiles
Shows RECYLE, should this be amended to RECYCLE? It doesn't appear in the $options debugger output.
If I add NODIALOG & RECYLE it doesn't send to the recycle bin. I thought it would ???
Lastly .... how do you script to recurse subdirs from GetSourcePath etc?