Archive::Rar - Interface with the 'rar' command
Windows
Linux
use Archive::Rar; my $rar = Archive::Rar->new(); $rar->Add( -size => $size_of_parts, -archive => $archive_filename, -files => \@list_of_files, );
To extract files from archive:
use Archive::Rar; my $rar = Archive::Rar->new( -archive => $archive ); $rar->List( ); my $res = $rar->Extract( ); print "Error $res in extracting from $archive\n" if ( $res );
To list archived files:
use Archive::Rar; my $rar = Archive::Rar->new( -archive => $archive ); $rar->List( ); $rar->PrintList( );
Using further options:
use Archive::Rar; my $rar = Archive::Rar->new( -archive => $archive ); my $res = $rar->Extract(-donotoverwrite => 1, -quiet => 1 ); print "Error $res in extracting from $archive\n" if ( $res );
This is a module for the handling of rar archives.
Locates the rar command (from PATH or from regedit for Win32) and encapsulate it to create, extract and list rar archives.
Note: There are a few things that have gone awry. Have a look at the Archive::Rar::Passthrough module that is part of this distribution. It is a lower-level interface to the rar command, but it does some things in a safer way than this module (namely shell escaping or lack thereof).
rar
At the moment these methods are implemented:
new()
Returns a new Rar object. You can pass defaults options.
Add(%options)
Add file to an archive.
Extract(%options)
Extract the contains of an archive.
List(%options)
Fill the 'list' variable of the object whith the index of an archive. Returns 0 on success or a numerical error code.
PrintList(%options)
Prints the file contents list that was previously generated using List() to STDOUT.
List()
GetBareList(%options)
Returns an array with the file contents list that was previously generated using List(). Adding the -excludepaths option and setting it to true, the pathnames will be excluded and a simple basename of the listed files will be returned.
-archive
Archive filename.
-files
List of files to add. You can use a scalar value or an array reference.
-quiet
No output for the rar command if True.
-sfx
Create self-extracting archive.
-size
Size of the parts in bytes.
-verbose
Level of verbosity.
-excludepaths
Exclude paths from names.
-donotoverwrite
Do not overwrite existing files if True.
-lowprio
For Unix-like systems only, this options runs the extraction with low scheduling priority, if Ture.
As of the current version, the system commands calling 'rar' are assembled as a string. This means that some parameters which take a string may have problems with shell quoting.
jean-marc boulade <jmbperl@hotmail.com>
Copyright (c) 2002-2006 jean-marc boulade. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Modified by Steffen Mueller in 2007-2008. The changes carry the same license as stated above.
"C:/Program Files/WinRAR/rar.exe" RAR 2.80 Copyright (c) 1993-2001 Eugene Roshal 2 Mar 2001 Shareware version Type RAR -? for help Usage: rar <command> -<switch 1> -<switch N> <archive> <files...> <@listfiles...> <path_to_extract\> <Commands> a Add files to archive c Add archive comment cf Add files comment cw Write archive comment to file d Delete files from archive e Extract files to current directory f Freshen files in archive k Lock archive l[t] List archive [technical] m[f] Move to archive [files only] p Print file to stdout r Repair archive rr[N] Add data recovery record s[name|-] Convert archive to or from SFX t Test archive files u Update files in archive v[t] Verbosely list archive [technical] x Extract files with full path <Switches> - Stop switches scanning ac Clear Archive attribute after compression or extraction ag[format] Generate archive name using the current date ao Add files with Archive attribute set ap<path> Set path inside archive as Synchronize archive contents av Put authenticity verification (registered versions only) av- Disable authenticity verification check c- Disable comments show cfg- Disable read configuration cl Convert names to lower case cu Convert names to upper case df Delete files after archiving dh Open shared files ds Disable name sort for solid archive e<attr> Set file exclude attributes ed Do not add empty directories ep Exclude paths from names ep1 Exclude base directory from names ep2 Expand paths to full f Freshen files idp Disable percentage display ierr Send all messages to stderr ilog Log errors to file (registered versions only) inul Disable all messages isnd Enable sound k Lock archive kb Keep broken extracted files m<0..5> Set compression level (0-store...3-default...5-maximal) md<size> Set dictionary size in KB (64,128,256,512,1024 or A,B,C,D,E) mm[f] Multimedia compression [force] o+ Overwrite existing files o- Do not overwrite existing files os Save NTFS streams ow Save or restore file owner and group p[password] Set password p- Do not query password r Recurse subdirectories r0 Recurse subdirectories for wildcard names only ri<P>[:<S>] Set priority (0-default,1-min..15-max) and sleep time in ms rr[N] Add data recovery record s[<N>,d,e] Create solid archive s- Disable solid archiving sfx[name] Create SFX archive tk Keep original archive time tl Set archive time to latest file tn<time> Add files newer than <time> to<time> Add files older than <time> u Update files v Create volumes with size autodetection or list all volumes v<size>[k,b] Create volumes with size=<size>*1000 [*1024, *1] vd Erase disk contents before creating volume vp Pause before each volume w<path> Assign work directory x<file> Exclude specified file x@ Read file names to exclude from stdin x@<list> Exclude files in specified list file y Assume Yes on all queries z<file> Read archive comment from file
To install Archive::Rar, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Archive::Rar
CPAN shell
perl -MCPAN -e shell install Archive::Rar
For more information on module installation, please visit the detailed CPAN module installation guide.