#! /usr/bin/perl

my $slash="/";
if ( $^O =~ /Win32/ ) {
  $slash="\\";
}

sub del_files {
  my $dir = $_[0];
  opendir(DIR,$dir);
  my @img_f = grep { /png$/ } readdir(DIR);
  closedir(DIR);
  my $i=0;
  my $time_ref = time() - 3600;
  while($i <= $#img_f) {
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($dir.$slash.$img_f[$i]);
    if ($mtime <= $time_ref) {
#      print "On ne garde pas: ".$img_f[$i]."\n";
      unlink($dir.$slash.$img_f[$i]);
    }
    $i++;
  }
}

my $dir=shift;
my $tempo=shift;
$tempo = $tempo * 86400 if (defined($tempo));
die "$dir is not a directory.\n" if (! -d $dir);
del_files($dir,$tempo);
