11Sep/083
Recursive unrar unzip perl script
It's a bit hacky, but it works.
#!/usr/bin/perl
use File::Find;
use File::Spec;
if (@ARGV[0] eq '')
{
print "useage: $0 foldername\n";
}
else
{
print "Exctacting for folder ". $ARGV[0] ."\n";
find ( \&extract_dir , @ARGV[0]);
print (++$n,": $_\n") foreach (@elist) ;
}
exit;
sub extract_dir
{
next if -d $_;
next if /^\./;
my $ff = $File::Find::name;
# deal with RAR files
unrar($_,$ff);
#deal with ZIP files
if ($ff =~ /\.zip$/i )
{
print "unzip $ff";
system ('unzip','-qq', "$_");
if ($? != 0)
{
push (@elist, $ff);
}
else
{
print "\nrm -f $ff\n";
system ('rm', '-f', $_);
}
}
}
sub unrar
# takes filename, full filename
{
if ($_[0] =~ /\.rar$/i)
{
if ($_[0] =~ /\.part[0-9]+?\.rar$/i)
{
if ($_[0] =~ /\.part[0]+?1\.rar$/i)
{
print "unrar x $_[1] \n";
system ('unrar','x','-y','-inul', "$_[0]");
if ($? != 0)
{
push (@elist, "$_[1]");
}
else
{
my $todel = $_[0];
$todel =~ s/\.part[0]+?1\.rar$/\.part*\.rar/g ;
print "find ./ -name \"$todel\" -exec rm {} \\\;\n";
system ("find ./ -name \"$todel\" -exec rm {} \\\;");
}
}
}
else
{
print "unrar x $_[1] \n";
system ('unrar','x','-y','-inul', "$_[0]");
if ($? != 0)
{
push (@elist, "$_[1]");
}
else
{
my $todel = $_[0];
$todel =~ s/\.rar$/\.r*/g ;
print "find ./ -name \"$todel\" -exec rm {} \\\;\n";
system ("find ./ -name \"$todel\" -exec rm {} \\\;");
}
}
}
}













August 24th, 2009 - 05:53
love this script been using it ever since it was posted thanks a lot
October 16th, 2009 - 18:38
this is perfect!
thanks.
June 11th, 2010 - 12:35
Thanks!!!!