China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-05 15:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to batch-compress multiple folders View 2,350 Replies 11
Original Poster Posted 2007-08-23 13:58 ·  中国 湖北 仙桃 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
I have 50 folders under one folder.
Does anyone know how to use commands to compress each of them separately, preferably with passwords too, and run it in batch?
Compressing them one by one is too troublesome.

[ Last edited by hjkk123 on 2007-8-23 at 04:52 PM ]
Floor 2 Posted 2007-08-23 14:10 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Search for willsort
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 3 Posted 2007-08-23 14:18 ·  中国 湖北 仙桃 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
'willsort' is not recognized as an internal or external command, operable program
or batch file.

Can you post willsort, and also give me an example?
Floor 4 Posted 2007-08-23 14:20 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
....That's a forum member... he posted it before...

Take a look at RAR's command-line syntax
Floor 5 Posted 2007-08-23 14:41 ·  中国 湖北 仙桃 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
Originally posted by slore at 2007-8-23 02:20 PM:
....That's a forum member... he posted it before...

Take a look at RAR's command-line syntax

Oh, sorry, I got it wrong. willsort isn't a command, it's a member. He has posted too much stuff, it's like looking for a needle in the sea

[ Last edited by hjkk123 on 2007-8-23 at 02:52 PM ]
Floor 6 Posted 2007-08-23 14:53 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Floor 7 Posted 2007-08-23 15:00 ·  中国 湖北 仙桃 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
That's a lot, thanks!
So how do I solve my problem then? Please just help me write the code

[ Last edited by hjkk123 on 2007-8-23 at 03:07 PM ]
Floor 8 Posted 2007-08-23 15:11 ·  中国 湖北 仙桃 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
Maybe I need to use the for command? My eyes are a bit blurry right now, could someone write it out step by step? Everyone was fed by someone when they were little.
Floor 9 Posted 2007-08-23 15:27 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
@echo off
for /f "delims=" %%i in ('dir /ad /b') do (
"%programfiles%\winrar\rar.exe" a -hp12345 "%%i".rar "%%i"
)
pause


Assuming the OP's WINRAR path is like this.

[ Last edited by wudixin96 on 2007-8-23 at 04:09 PM ]
Floor 10 Posted 2007-08-23 15:59 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
I’m posting the code written by willsort.
:: RarExt.bat - Add separate compression function to WinRAR
:: Will Sort - 17:38 2005-3-27 - WinXP
:: 2005-4-1 3'rd Updated
@echo off
if %0=="%ProgramFiles%\WinRAR\RarExt.bat" goto Compress

:Configure
if not exist "%ProgramFiles%\WinRAR\Rar.exe" echo WinRAR not found, cannot configure! & goto end
if exist %0 copy %0 "%ProgramFiles%\WinRAR\RarExt.bat">nul
if exist %0.bat copy %0.bat "%ProgramFiles%\WinRAR\RarExt.bat">nul
if not exist "%ProgramFiles%\WinRAR\RarExt.bat" echo Failed to create batch file RarExt.bat! & goto end

reg add HKCR\*\shell\CompressRespectivelyWithRAR /ve /t REG_SZ /d "Compress all current files/folders separately into RAR files(&Y)" /f>nul
if errorlevel 1 echo Registry modification failed! & goto end
reg add HKCR\*\shell\CompressRespectivelyWithRAR\command /ve /t REG_SZ /d "%ProgramFiles%\WinRAR\RarExt.bat" /f>nul
if errorlevel 1 echo Registry modification failed! & goto end
reg add HKCR\Folder\shell\CompressRespectivelyWithRAR /ve /t REG_SZ /d "Compress all files/folders under this folder separately into RAR files(&Y)" /f>nul
if errorlevel 1 echo Registry modification failed! & goto end
reg add HKCR\Folder\shell\CompressRespectivelyWithRAR\command /ve /t REG_SZ /d "%ProgramFiles%\WinRAR\RarExt.bat \"%%L\"" /f>nul
if errorlevel 1 echo Registry modification failed! & goto end
echo Successfully set the WinRAR separate compression option. You can use this function from the right-click menu on files or folders!
pause
goto end

:Compress
for /d %%d in (%1.\*.*) do "%ProgramFiles%.\WinRAR\rar" a -r -inul %1.\"%%~nxd.rar" "%%~nxd"
for %%f in (%1.\*.*) do "%ProgramFiles%.\WinRAR\rar" a -r -inul %1.\"%%~nf.rar" "%%~nxf"

:end
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 11 Posted 2007-08-23 16:04 ·  中国 湖北 仙桃 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
How do I add a password?
Floor 12 Posted 2007-08-23 16:07 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
How to add a password was already posted in reply #6.

:Compress
for /d %%d in (%1.\*.*) do "%ProgramFiles%.\WinRAR\rar" a -r -hp123 -inul %1.\"%%~nxd.rar" "%%~nxd"
for %%f in (%1.\*.*) do "%ProgramFiles%.\WinRAR\rar" a -r -hp123 -inul %1.\"%%~nf.rar" "%%~nxf"

This way, 123 is the password.

[ Last edited by ccwan on 2007-8-23 at 04:12 PM ]
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Forum Jump: