How to create separate archive for sub folder?

Gon

Well-Known Member
427
127
43
2014
i have 3 main folder

Code:
test1
test2
test3
inside these folder there is sub folders.
Code:
test1/1
test1/2
test1/3
test2/1
test2/2
test2/3
test3/1
test3/2
test3/3
i want to archive all subfolder separately.

Code:
test1/1.rar
test1/2.rar
test1/3.rar
test2/1.rar
test2/2.rar
test2/3.rar
test3/1.rar
test3/2.rar
test3/3.rar
after archive done delete subfolders. any help please?
 
Last edited:
5 comments

Hyperz

Well-Known Member
2,266
233
63
2009
This probably belongs in the development forum. Anyway, save the script below as a *.bat file, edit the root folder (containing your "main folders") and Rar.exe paths if needed, and run it:

Code:
@ECHO OFF

REM === CONFIG ===

SET rar_executable=C:\Program Files\WinRAR\Rar.exe
SET root_folder=C:\path\to\root\folder

REM === CODE ===

ECHO.
ECHO ##########################################################
ECHO  Using WinRAR executable: %rar_executable%
ECHO  Root folder: %root_folder%
ECHO ##########################################################
ECHO.

FOR /D %%F IN ("%root_folder%\*") DO (
    
    ECHO.
    ECHO Switching to folder '%%F'
    
    FOR /D %%S IN ("%%F\*") DO (
    
        ECHO Archiving folder '%%S'
        %rar_executable% a -r -ep1 "%%F\%%~nxS.rar" "%%S"
        RMDIR /s /q "%%S"
    )
    
    ECHO.
    
)

PAUSE
 
  • Like
Reactions: Gon

Gon

Well-Known Member
427
127
43
2014
thank you but i got this error. winrar path is correct. and after run the bat file all sub folder deleted. not sure if folder rar and saved in somewhere.
Code:
##########################################################
 Using WinRAR executable: C:\Program Files\WinRAR\Rar.exe
 Root folder: N:\work\pic\gon
##########################################################


Switching to folder 'N:\work\pic\gon\tear2'
Archiving folder 'N:\work\pic\gon\tear2\test'
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Archiving folder 'N:\work\pic\gon\tear2\Unbelievable.S01E01.iNTERNAL.1080p.WEB.X264-AMRAP_s'
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.


Switching to folder 'N:\work\pic\gon\test'
Archiving folder 'N:\work\pic\gon\test\test'
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Archiving folder 'N:\work\pic\gon\test\Unbelievable.S01E01.iNTERNAL.1080p.WEB.X264-AMRAP_s'
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Press any key to continue . . .
 
Last edited:

Gon

Well-Known Member
427
127
43
2014
ok i guess "C:\Program Files" may be the space made error. i moved rar to C:\ and changed the path C:\rar.exe
now worked. thanks a lot
 
Last edited:

Hyperz

Well-Known Member
2,266
233
63
2009
Ah, yeah forgot to add quotes to this line:

Code:
"%rar_executable%" a -r -ep1 "%%F\%%~nxS.rar" "%%S"
That should make it work with spaces in the path.
 
  • Like
Reactions: Gon

Gon

Well-Known Member
427
127
43
2014
sorry for bumping old topic. need one more help. previous one was for subfolder. but how to make it work for single folder.

i have 3 folder with file name

Code:
test1/1.mkv
test1/2.mkv
test1/3.mkv
test2/1.mkv
test2/2.mkv
test2/3.mkv
test3/1.mkv
test3/2.mkv
test3/3.mkv
want to archive included all files inside the folder and make follow archive using folder name
Code:
test1.rar
test2.rar
test3.rar
example test1.rar archive will contain
Code:
test1/1.mkv
test1/2.mkv
test1/3.mkv
 
Top Bottom