I am trying to make a script which will delete files older than a year.
This is my code:
#!/usr/bin/perl
$files = ".dat|.exe";
@file_del = split('\|',$files);
print "@file_del";
$dates = "365|365|365|365";
@date_del = split('\|',$dates);
if($#date_del == 0){
for $i (@file_del){
my $f = `find \"/Users/ABC/Desktop/mydata\" -name *$i -mtime +date[0]`;
print "$f";
}
}
else{
for $i (0..$#file_del){
my $f = `find \"/Users/ABC/Desktop/mydata\" -name *$file_del[$i] -mtime +$date_del[$i]`;
print "$f";
}
}
Issues I am facing:
- It is not detecting .txt files, otherwise .data,.exe,.dat etc it is detecting.
- Also -mtime is 365. But a leap year(366 days) I have to change my script.
You can also use the command
find2perl
. Like:What will produce a perl script to use the
File::Find
- e.g.:Use the brilliant Path::Class to make life easy: