Friday, December 12, 2008

Automate self-extraction file using Rar (WinRar)

Purpose: We have several directories and we want to automate packing process for all of directories specified in configuation file to be each self-extraction.
To make the self extraction file for DVD installer using Rar.exe (console version of WinRar)

%dirZipNames is the hash which contains the list of input directories and output file names.
$rarPath is the executable "Rar.exe" and its path.
$inputDir is the directory which contains the input directories for packing.


## Start packing..
for $_ (keys %dirZipNames) {
my $dir = $inputDir . "\\" . $_;
my $zipExe = $inputDir . "\\" . $dirZipNames{$_} . ".exe";
if ( -d $dir && ! -e $zipExe) {
my $dirAll = $dir . "\\*.*";
print "Start packing $dirAll ...proceeding...\n";
print "Or check the progress in make_exe.log...";
system (qq{"$rarPath" a -r -m5 -sfx "$zipExe" "$dirAll" >> "$inputDir\\make_exe.log"});
print "\nOK: $zipExe is done!\n";
else {
print "\nError: Directory $dir does not exist \n\tor the $zipExe is already created!\n";