#!/sw/bin/perl -w
############################
# By: Ventz Petkov         #
# Date: 7-08-05            #
# Massive File Search/Grab #
############################
use strict;
use File::Find::Rule;
use File::Copy;

my ($rule, $file, $newfile, @newfile);
if (@ARGV != 3) {
    print "\t\tUsage: ./grab.pl start_directory dump_directory file_extension\n";
    print "\t\tEx: ./grab.pl /home/ventz /tmp mp3\n"; exit();
}

$rule = File::Find::Rule->file->name("*.".$ARGV[2])->start( "$ARGV[0]" );
while ( $newfile = $file = $rule->match ) {
    print "$file\n";
    @newfile = split("/", $newfile);
    copy($file, $ARGV[1]."/".@newfile[scalar(@newfile)-1]) or die "File cannot be copied.";
}
