A voir également:
- PERL : Supprimer fichiers avec critère date
- Denon perl pro test - Accueil - Audio
- Active perl - Télécharger - Édition & Programmation
- DzSoft Perl Editor - Télécharger - Édition & Programmation
- Comment lire un fichier .pl perl ? - Forum Windows
- Perl: transformer un fichier en package ✓ - Forum Perl
1 réponse
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));
}