gavinandrewmcmillan
asked on
Batch file for WinRAR
Hi all
Im wondering if anyone knows of or has written a batch file that will run winrar and make it compress a group of files. im looking at creating a batch file that will basically open winrar, set the settings i want and then start compressing files ready for backing up. If anyone has done this could you please let me know how, and if knowone has, could someone please point me in the right direction of how i could go about doing it?
Im wondering if anyone knows of or has written a batch file that will run winrar and make it compress a group of files. im looking at creating a batch file that will basically open winrar, set the settings i want and then start compressing files ready for backing up. If anyone has done this could you please let me know how, and if knowone has, could someone please point me in the right direction of how i could go about doing it?
WinRAR has a command line capability - I've not used it, but I know it's there and this should be relatively easy.
A simple example for a batch file that compresses a folder:
--- test.bat
cd c:\mp3
winrar a -s mymusic.rar *.*
---- end of test.bat
This simply moves to a specific folder and adds all it's files to a solid archive named mymusic.rar.
There is a many Commands and Switches you can use. There's a list in the winrar documentation file but you would have to find it. Here is a short list:
Invocation format:
WinRAR <command> -<switch1> -<switchN> <archive> <files...> <@listfiles...> <path_to_extract\>
Commands:
a add files to an archive
c add an archive comment
d delete files from an archive
e extract files from an archive, ignoring paths
f freshen files within an archive
i find string in archives
k lock an archive
m move files and folders to an archive
r repair a damaged archive
rc reconstruct missing volumes
rn rename archived files
rr[N] add data recovery record
rv[N] create recovery volumes
s[name] convert an archive to a self-extracting type
s- remove SFX module
t test archive files
u update files within an archive
x extract files from an archive with full paths
Switches:
-ac clear Archive attribute after compression or extraction
-ad append archive name to destination path
-af<type> specify archive format
-ag[format] generate archive name using the current date and time
-ao add files with Archive attribute set
-ap set path inside archive
-as synchronize archive contents
-av apply authenticity verification
-av- disable adding authenticity verification
-cfg- ignore default profile and environment variable
-cl convert file names to lower case
-cu convert file names to upper case
-df delete files after archiving
-dh open shared files
-ds do not sort archiving files
-ed do not add empty folders
-en do not add "end of archive" block
-ep exclude paths from names
-ep1 exclude base folder from names
-ep2 expand paths to full
-ep3 expand paths to full including the drive letter
-e<attr> set file exclude attributes
-f freshen files
-hp[pwd] encrypt both file data and headers
-ibck run WinRAR in background
-ieml send archive by email
-iicon<name> specify SFX icon
-ilog[name] log errors to file
-inul disable error messages
-ioff turn PC off
-k lock archive
-kb keep broken extracted files
-m<n> set compression method
-mc<par> set advanced compression parameters
-md<n> select dictionary size
-ms specify file types to store
-oc set NTFS "Compressed" attribute
-os save NTFS streams
-ow process file security information
-o+ overwrite existing files
-o- do not overwrite existing files
-p[pwd] set password
-r recurse subfolders
-r0 recurse subfolders for wildcard names only
-ri set priority and sleep time
-rr[N] add data recovery record
-rv[N] create recovery volumes
-s create a solid archive
-s<N> create solid groups using file count
-se create solid groups using file extension
-sfx[name] create self-extracting archive
-sv create independent solid volumes
-sv- create dependent solid volumes
-s- disable solid archiving
-t test files after archiving
-ta<date> process files modified after the specified date
-tb<date> process files modified before the specified date
-tk keep original archive time
-tl set archive time to newest file
-tn<time> process files newer than the specified time
-to<time> process files older than the specified time
-ts<m,c,a> save or restore file time (modification, creation, access)
-u update files
-v<n>[k|b|f|m|M|g|G] create volumes
-vd erase disk contents before creating volume
-ver file version control
-vn use the old style volume naming scheme
-vp pause before each volume
-x<file> exclude the specified file
-x@<listfile> exclude files using a specified list file
-y assume Yes on all queries
-z<file> read archive comment from file
-- stop switches scanning
You can find this info with good descriptions in the documentation. Just search for "command line syntax" and do forward.
--- test.bat
cd c:\mp3
winrar a -s mymusic.rar *.*
---- end of test.bat
This simply moves to a specific folder and adds all it's files to a solid archive named mymusic.rar.
There is a many Commands and Switches you can use. There's a list in the winrar documentation file but you would have to find it. Here is a short list:
Invocation format:
WinRAR <command> -<switch1> -<switchN> <archive> <files...> <@listfiles...> <path_to_extract\>
Commands:
a add files to an archive
c add an archive comment
d delete files from an archive
e extract files from an archive, ignoring paths
f freshen files within an archive
i find string in archives
k lock an archive
m move files and folders to an archive
r repair a damaged archive
rc reconstruct missing volumes
rn rename archived files
rr[N] add data recovery record
rv[N] create recovery volumes
s[name] convert an archive to a self-extracting type
s- remove SFX module
t test archive files
u update files within an archive
x extract files from an archive with full paths
Switches:
-ac clear Archive attribute after compression or extraction
-ad append archive name to destination path
-af<type> specify archive format
-ag[format] generate archive name using the current date and time
-ao add files with Archive attribute set
-ap set path inside archive
-as synchronize archive contents
-av apply authenticity verification
-av- disable adding authenticity verification
-cfg- ignore default profile and environment variable
-cl convert file names to lower case
-cu convert file names to upper case
-df delete files after archiving
-dh open shared files
-ds do not sort archiving files
-ed do not add empty folders
-en do not add "end of archive" block
-ep exclude paths from names
-ep1 exclude base folder from names
-ep2 expand paths to full
-ep3 expand paths to full including the drive letter
-e<attr> set file exclude attributes
-f freshen files
-hp[pwd] encrypt both file data and headers
-ibck run WinRAR in background
-ieml send archive by email
-iicon<name> specify SFX icon
-ilog[name] log errors to file
-inul disable error messages
-ioff turn PC off
-k lock archive
-kb keep broken extracted files
-m<n> set compression method
-mc<par> set advanced compression parameters
-md<n> select dictionary size
-ms specify file types to store
-oc set NTFS "Compressed" attribute
-os save NTFS streams
-ow process file security information
-o+ overwrite existing files
-o- do not overwrite existing files
-p[pwd] set password
-r recurse subfolders
-r0 recurse subfolders for wildcard names only
-ri set priority and sleep time
-rr[N] add data recovery record
-rv[N] create recovery volumes
-s create a solid archive
-s<N> create solid groups using file count
-se create solid groups using file extension
-sfx[name] create self-extracting archive
-sv create independent solid volumes
-sv- create dependent solid volumes
-s- disable solid archiving
-t test files after archiving
-ta<date> process files modified after the specified date
-tb<date> process files modified before the specified date
-tk keep original archive time
-tl set archive time to newest file
-tn<time> process files newer than the specified time
-to<time> process files older than the specified time
-ts<m,c,a> save or restore file time (modification, creation, access)
-u update files
-v<n>[k|b|f|m|M|g|G] create volumes
-vd erase disk contents before creating volume
-ver file version control
-vn use the old style volume naming scheme
-vp pause before each volume
-x<file> exclude the specified file
-x@<listfile> exclude files using a specified list file
-y assume Yes on all queries
-z<file> read archive comment from file
-- stop switches scanning
You can find this info with good descriptions in the documentation. Just search for "command line syntax" and do forward.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok nice work, next problem, how do i get into winrar comand line to put in the commands, i have tried to write the batch file the same as what you have done but it didnt work! could you show me the exact code that i would need to enter into the batch file to make it work.
Thanks
Thanks
ASKER
ok i just got it to work but i have a problem, here is my code:
Del c:\backup\*.rar
pause
set path=C:\program files\winrar\;%path%
cd C:\backup
winrar a -s backup.rar *.*
pause
Del C:\Documents and Settings\Administrator\Des ktop\Backu ps\*.*
pause
Copy c:\backup\backup.rar C:\Documents and Settings\Administrator\Des ktop\backu ps\
pause
I inserted the pauses so that i could see where it goes wrong, it goes wrong on the last delete and the copy, it says that it cant find the specified path (C:\Documents and Settings\Administrator\Des ktop\Backu ps\*.*) can anyone see any mistakes i have made or do you know what im doing wrong?
Regards
Gavin
Del c:\backup\*.rar
pause
set path=C:\program files\winrar\;%path%
cd C:\backup
winrar a -s backup.rar *.*
pause
Del C:\Documents and Settings\Administrator\Des
pause
Copy c:\backup\backup.rar C:\Documents and Settings\Administrator\Des
pause
I inserted the pauses so that i could see where it goes wrong, it goes wrong on the last delete and the copy, it says that it cant find the specified path (C:\Documents and Settings\Administrator\Des
Regards
Gavin
ASKER
it also says that the context isnt right for the copy comand aswell.
Change
Del C:\Documents and Settings\Administrator\Des ktop\Backu ps\*.*
to
Del "C:\Documents and Settings\Administrator\Des ktop\Backu ps\*.*"
and
Copy c:\backup\backup.rar C:\Documents and Settings\Administrator\Des ktop\backu ps\
to
Copy "c:\backup\backup.rar C:\Documents and Settings\Administrator\Des ktop\backu ps\"
DOS uses space to seperate parameters. When you have a path with space inside, you have to write it in between quotes.
Del C:\Documents and Settings\Administrator\Des
to
Del "C:\Documents and Settings\Administrator\Des
and
Copy c:\backup\backup.rar C:\Documents and Settings\Administrator\Des
to
Copy "c:\backup\backup.rar C:\Documents and Settings\Administrator\Des
DOS uses space to seperate parameters. When you have a path with space inside, you have to write it in between quotes.