//Using a batch file to automatically compress files of the same type or folders using 7-zip

Using a batch file to automatically compress files of the same type or folders using 7-zip

Compressing files of the same type
===============================
@echo off
cd /d %~dp0
rem 7z.exe path
set sevenzip=
if “%sevenzip%”==”” if exist “%ProgramFiles(x86)%\7-zip\7z.exe” set sevenzip=%ProgramFiles(x86)%\7-zip\7z.exe
if “%sevenzip%”==”” if exist “%ProgramFiles%\7-zip\7z.exe” set sevenzip=%ProgramFiles%\7-zip\7z.exe
if “%sevenzip%”==”” echo 7-zip not found&pause&exit
set extension=.xls
for %%a in (*%extension%) do “%sevenzip%” a -mx “%%~na.7z” “%%a”
pause
Change the extension for the type of file being compressed.

Compressing folders
===============================

for /d %%X in (*) do “c:\Program Files\7-Zip\7z.exe” a -mx “%%X.7z” “%%X\”

Paste the code into notepad, and save as .bat file. Double click to start the batch process.

2018-08-10T14:20:04+00:00