#!/star/Perl/bin/perl
use File::Find;

$tmpDir=$ARGV[0];
$maxAge=$ARGV[1];
if ($maxAge eq ""){
    $maxAge=2.0;
}

print "$maxAge \n";
chomp($tmpDir);
print "$tmpDir\n";

if ( $tmpDir =~ /tmp/ || $tmpDir =~ /temp/){ 

#opendir(DELE, $tmpDir) or die "Could not open directory\n";

print "directory opened\n";

find({wanted => \&wanted, no_chdir => 1}, $tmpDir) ;

}

else {
    print "NOT TMP TEMP\n";
}


sub wanted
{
$fullPath=$File::Find::name;
print "FULL $fullPath\n";
if ($fullPath ne $tmpDir && $fullPath =~ /[0-9]/ && !-d $fullPath) {
    $age = (-M $fullPath);
    if ($age >= $maxAge) {
    print "deleting $fullPath $age\n";
    unlink $fullPath;
}

}
if ($fullPath ne $tmpDir && $fullPath =~ /[0-9]/ && -d $fullPath) {
    print "$fullPath removing  dir\n";
    rmdir $fullPath;

}
}
