PERL : Supprimer fichiers avec critère date

JLX -  
grofwa Messages postés 440 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
Je souhaite supprimer tous les fuichiers d'un répertoire ayant plus de 3 mois. Quelles fonctions utiliser sous PERL pour effectuer cela.

Merci
A voir également:

1 réponse

grofwa Messages postés 440 Date d'inscription   Statut Membre Dernière intervention   479
 
En shell unix : find . -atime +90 -exec rm {} ;

Tu peux utiliser ce petit script trouvé sur http://pubcrawler.org/archives/000032.html :

#!/usr/bin/perl -l
# Script: cleanup.pl
# Author: Jamin P. Gray
# Purpose: Will cleanup directories by deleting files older than a given number of days
# Usage: cleanup.pl -t <days> <dir>
use Getopt::Long;
Getopt::Long::Configure("bundling");
GetOptions("time|t=n", "noprompt|n", "help|?");
if (!defined($directory = pop) || defined($opt_help)) {
printf <<'END';
Usage: cleanup.pl [OPTIONS] [DIRECTORY]
Cleanup a directory by deleting files older than a given day.
-t, --time=N delete files older than N days
-n, --noprompt do not prompt before deleting
--help display this help and exit
END
exit(0);
}
$days = defined($opt_time) ? $opt_time : 14; # defaults to two weeks
$seconds = $days * 86400;
unless (defined($opt_noprompt)) {
print "This will delete all files older than $days days.";
print "Do you wish to continue (Y/N)?";
if (lc <STDIN> ne "y
") {
die "exiting...";
}
}
for (glob("$directory/*")) {
unlink if (-f && (time - (stat($_))[9] >= $seconds));
}
2