All pastes #472963 Raw Edit

Something

public text v1 · immutable
·published 2007-05-05 23:10 UTC
rendered paste body
#!/usr/bin/perl

use strict;
use File::Find;
use Data::Dumper;

my %hash;
my @remove_files;

opendir DIR, "./" or die "Bad dir : $!\n";
my @directories = readdir(*DIR);
my @fixed_dirs;
map { push ( @fixed_dirs, $_ ) if ( $_ !~ /^\.+$/) && -d $_ } @directories;
print "FIXED:  ",join("\n",@fixed_dirs),"\n";

my %options = ( preprocess => sub { sort { reverse $a cmp reverse $b } @_ } );
find( \%options , @fixed_dirs);
find(\&wanted, @fixed_dirs) ;
close DIR;
print "Next\n";
print Dumper(%hash);

sub wanted {
        if ( /(\.part\d\d)*\.([ra\d]{3})$/ ) {
                if ( ! $hash{$File::Find::dir}{'done'} ) {
                        my $origfile = $_;
                        $_ =~ s/(\.part\d\d)*\.([ra\d]{3})|(\d{3})$//;
                        my $shortname = $_;
                        if ( ! map { $shortname eq $_ } @{$hash{$File::Find::dir}{'done'}} ) {
                                push ( @{$hash{$File::Find::dir}{'extracted'}}, $origfile);

                                print "unrar e -o- $origfile\n";
                                push ( @{$hash{$File::Find::dir}{'done'}}, $shortname);

                        }
                }
        }
}