Skip to content

Instantly share code, notes, and snippets.

@nimaid
Last active October 25, 2020 19:58
Show Gist options
  • Select an option

  • Save nimaid/db47812d5165ed86cd74eda448759387 to your computer and use it in GitHub Desktop.

Select an option

Save nimaid/db47812d5165ed86cd74eda448759387 to your computer and use it in GitHub Desktop.
A batch script to get the best possible 7z compression. (USE WITH REDUNDANCY, EASILY CORRUPTIBLE)
@echo off
set exe_7z=C:\Program Files\7-Zip\7z.exe
REM https://superuser.com/questions/281573/what-are-the-best-options-to-use-when-compressing-files-using-7-zip
REM best for <16GB of RAM
set command_7z=a -mx=9 -mfb=273 -ms=on
REM second best for <16GB of RAM, faster
REM set command_7z=a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on
REM supposedly better if you have lots of RAM, but I got similar results to the first one
REM set command_7z=a -t7z -mx=9 -mfb=273 -ms -md=31 -myx=9 -mtm=- -mmt -mmtf -md=1536m -mmf=bt3 -mmc=10000 -mpb=0 -mlc=0
if [%1]==[] (
echo.
echo No file/folder path supplied!
goto USAGE_MSG
) else (
set FOLDER_PATH=%1
)
if [%2]==[] (
echo.
echo No archive name supplied!
goto USAGE_MSG
) else (
set ARCHIVE_PATH=%2
)
set final_command="%exe_7z%" %command_7z% "%ARCHIVE_PATH%" "%FOLDER_PATH%"
echo Running compression command:
echo %final_command%
%final_command%
if errorlevel 1 goto ERROR
echo.
echo Compressed %2 =^> %1
goto END
:USAGE_MSG
echo.
echo Program usage:
echo.
echo best_compress path archive
echo.
echo path The path of the file/folder to archive.
echo archive The name of the resultant archive.
echo.
goto END
:ERROR
echo.
echo There was an error while compressing.
goto END
:END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment