How to Auto RaR Files

Status
Not open for further replies.

cotufa-ssdd

Active Member
387
2011
82
0
Hello WJ!

I recently saw a new thread asking about how to rar files automatically

So I decided to make a little tutorial that may help many, hope it does:

My technique uses a BATCH script I made and a scheduled task involving this BATCH file.

So first open up notepad or your favorite text editor

Type the following:


@ECHO OFF

cd C:\directory_with_files_you_want_to_compress

SET PATH=C:;C:\Program Files (x86)\WinRAR;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;%PATH%

FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep -df "C:\where_you_want_to_save_new_rar_files\%%~nxd.rar" "%%~fd"

EXIT


Save this as AutoRaR.bat (or whatever you want) and save it where you want

So the first path ¨C:\directory_you_want_to_compress¨ is the directory where the files you want to compress are located

SET PATH looks for rar.exe to run in command prompt
DO NOT EDIT THIS

DO WinRar executes winrar
-m0 is the compression level, where compresion level (0-store...3-default ...5-maximal) you can set which ever you want

-ep excludes the path from the created rar name (You can remove if you want to include path)

-df deletes the original files in the main directory you set first ¨C:\directory_you_want_to_compress¨
You can remove this if you want to maintain the files and remove manually later

Example:
[SLIDE]http://i48.tinypic.com/2qib6mu.png[/SLIDE]


Now create a new scheduled task to run AutoRaR.bat for example hourly, daily, weekly or whatever your needs

To create a new scheduled task go Start>All Programs>Accessories>System Tools>Task Scheduler and from here follow the wizard

Thats it Folks! Hope I helped!

Enjoy
cotufa-ssdd​

NOTE: I have provided this as open source for anyone to use and modify
Please test before using on your original files

::EDIT::

I added suggestions tha WJ members have requested to the primary post:



EXCLUDE RAR FILES FROM RE-COMPRESSION:

@ECHO OFF​

cd C:\directory_with_files_you_want_to_compress​

SET PATH=C:;C:\Program Files (x86)\WinRAR;C:\Windows\system32;C:\Windows;C:\Win dows\System32\Wbem;%PATH%​

FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep -df -x*.rar "C:\where_you_want_to_save_new_rar_files\%%~nxd.rar" "%%~fd"​

move /-y "C:\directory_with_files_you_want_to_compress\*.rar" "C:\where_you_want_to_save_new_rar_files\"
EXIT​

Where -x*.rar means ¨exclude all .rar files¨. You can add more files to exclude for example add another -x*.zip​

Since you excluded all rar files, they will stay in the original directory, thats what the next code does, move, this is simply moving all .rar files to the same directory where the compressions are being made.​



COMPRESS IN MULTIVOLUMES:

Edit this line:​

FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep -df -x*.rar -v100m "C:\where_you_want_to_save_new_rar_files\%%~nxd.rar" "%%~fd"​

-v100m will save multivolumes of 100m. Or change to whatever you need..​



ADD README, INSTRUCTION OR ANY ¨BASE¨ FILE TO ALL COMPRESSIONS:

@ECHO OFF​

for /D %%f in ("C:\directory_with_files_you_want_to_compress\*") do copy "C:\directory_with_readme.txt\readme.txt" "%%f\"

cd C:\directory_with_files_you_want_to_compress​

SET PATH=C:;C:\Program Files (x86)\WinRAR;C:\Windows\system32;C:\Windows;C:\Win dows\System32\Wbem;%PATH%​

FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep -df -v100m -x*.rar "C:\where_you_want_to_save_new_rar_files\%%~nxd.rar" "%%~fd"​

EXIT​

This new line will add the readme.txt to all original folders before compression. It then moves on to compress each folder to the specifications discussed earlier.​

Notice that the readme.txt is located in a diferent directory, that is so it will not be compressed and removed.​



UNRAR PASSWORDED FILES:

ECHO OFF​

cd C:\PATH TO RARS​

SET PATH=C:;C:\Program Files (x86)\WinRAR;C:\Windows\system32;C:\Windows;C:\Win dows\System32\Wbem;%PATH%​

FOR /f "delims=" %%d IN ('DIR /B') DO unRaR e -p123456 *.rar C:\DESTINATION TO EXTRACT​

EXIT​

123456 is the password and it is the same password for *all rars.​

Enjoy
cotufa-ssdd​

NOTE: I have provided this as open source for anyone to use and modify
Please test before using on your original files


::::EDIT::::

Hi guys here is a new addition based on user request:


Create Backups Without overwriting Previous Files


-ag[format]

Add date to name to create unique files and not overwrite previous ones!


Format:


Y – year
M – month
MMM – month name as text string (Jan, Feb, etc.)
W – a week number (a week starts with Monday)
A – day of week number (Monday is 1, Sunday – 7)
D – day of month
E – day of year
H – hours
M – minutes (treated as minutes if encountered after hours)
S – seconds
N – archive number. RAR searches for already existing archive
with generated name and if found, increments the archive
number until generating a unique name. ‘N’ format character
is not supported when creating volumes.



Examples:


1) use the default YYYYMMDDHHMMSS format


DO WinRAR a -m0 -ep -ep1 -r-ag backup



2) use DD-MMM-YY format


DO WinRAR a -m0 -ep -ep1 -r -agDD-MMM-YY backup



3) use YYYYMMDD and the archive number. It allows to generate
unique names even when YYYYMMDD format mask used more than
once in the same day


DO WinRAR a -m0 -ep -ep1 -r-agYYYYMMDD-NN backup

Hope it helped!

Enjoy
cotufa-ssdd

NOTE: I have provided this as open source for anyone to use and modify
Please test before using on your original files


 
Last edited:
64 comments
hello. if i want when file archived with name seem "filename.rar" how to do that. beacause when i archived all files look like ... "filename.mp4.rar.part1" or "filename.exe.rar" i want remove .mp4 or .exe on final archive.
 
Last edited:
can anyone tell how it works under linux shell?

Code:
@ECHO OFF

for /D %%f in ("C:\rar\unR\*") do copy "C:\a\*.*" "%%f\"  

cd C:\rar\unR  

SET PATH=C:\Program Files\WinRAR;%PATH%  

FOR /f "delims=" %%d IN ('DIR /B') DO RAR a -m0 -ep1 -r -rr3p -hpmeyer83 -zC:\meye83.txt -k -t -dw -ierr "C:\rar\upp\%%~nxd-unR.rar" "%%~fd"

EXIT
 
@Mozilla

Remove this ¨X¨:

@ECHO OFF

cd C:\Users\YOU\Desktop\1
SET PATH=C:;C:\Program Files (x86)\WinRAR;C:\Windows\system32;C:\Windows;C:\Win dows\System32\Wbem;%PATH%
FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep "C:\Users\YOU\Desktop\2\%%~nxd.rar" "%%~fd"

EXIT

This will remove extensions from filename, BUT, if you have files with same name and diferent extensions it will RAR into one common file.

Example: Separate files in same folder
Movie.avi, Movie.srt, Movie.png, Movie.nfo
Will RaR into 1 file Movie.rar

See Image Bellow:

Normal Results
[SLIDE]http://i.imgur.com/o9NwZWL.png[/SLIDE]

After Removing X
[SLIDE]http://i.imgur.com/5btUXCW.png[/SLIDE]

Hope it helps!
 
I think this is the simplest way to do auto rar files.

This is how you do this: select all folders/files -> right click -> Add to archive... -> Files tab -> tick Put each file to separate archive

This is my 1000th post.
 
Last edited:
Hi guys, need your help for auto rar scrip below,

example:
I have files in folder(X), after run autorar script then the rar files will created in folder(Y), after AutoRar run completed I want the original files from folder(X) automatically move to folder(Z).

Now, the scrip below is already running perfectly, I just need the last step which is to move the original file to another folder after running the scrip.

@ECHO OFF




cd D:\file_here*


SET PATH=C:;C:\Program Files\WinRAR;C:\Windows\system32;C:\Windows;C:\Win dows\System32\Wbem;%PATH%


FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep1 -x*.rar -v340m "D:\Ready\%%~nxd.rar" "%%~fd"


EXIT

Thanks in advance for your help!!
 
HI Hapalon

just add this line and edit to your needs

move /-y "C:\directory_with_files_you_want_to_compress\" "C:\where_you_want_to_save_new_rar_files\"
 
guyz anyone here can help me ?

i have tried it but not working ! :(

i think that there's something wrong , but i dunno what is it :(
 
Hi D4rk, I got your PM, sorry I couldn´t get back to you sooner, I am glad to help. I will post an answer to your question as son as I can... Regards!
 
Status
Not open for further replies.
Back
Top