PERL : Supprimer fichiers avec critère date
Fermé
JLX
-
4 déc. 2003 à 13:31
grofwa Messages postés 440 Date d'inscription jeudi 24 juillet 2003 Statut Membre Dernière intervention 21 juillet 2006 - 4 déc. 2003 à 14:58
grofwa Messages postés 440 Date d'inscription jeudi 24 juillet 2003 Statut Membre Dernière intervention 21 juillet 2006 - 4 déc. 2003 à 14:58
A voir également:
- PERL : Supprimer fichiers avec critère date
- Supprimer compte instagram - Guide
- Supprimer une page word - Guide
- Wetransfer gratuit fichiers lourd - Guide
- Supprimer compte facebook - Guide
- Iphone 14 date de sortie - Guide
1 réponse
grofwa
Messages postés
440
Date d'inscription
jeudi 24 juillet 2003
Statut
Membre
Dernière intervention
21 juillet 2006
479
4 déc. 2003 à 14:58
4 déc. 2003 à 14:58
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));
}
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));
}