Can someone help me out ? I'm trying to write a script which deletes
files in a certain directory on the server, that are older than let's
say 30 day's. I just can't seem to get the code right... Is there
anybody out there who has the lines available for me ?
Thanks in advance
Sent via Deja.com http://www.deja.com/
Before you buy.
You'll find examples of that in the various perl cookbooks.
One thing that keeps tripping people up is attempting to do a readdir()
on anything but ".". If the directory you're looking at is not your
current directory, make it your current directory first.
chdir
opendir, readdir, closedir
foreach directory_entry, stat or -M, then unlink unless -d
-Joe
--
INWAP.COM is Joe Smith, Sally Smith and our cat Murdock.
See http://www.inwap.com/ for PDP-10, "ReBoot", "Shadow Raiders"/"War Planets"
use File::Find
$dir="x:";
$days=60;
find sub {push @old_files, $File::Find::name if (-M $File::Find::name >
$days && -f $File::Find::name) },$dir;
After this you have in the @old_files array all the files older than $days
in the directory $dir.
Then you can do unlink() that all those files.
You could do too:
find sub {unlink($File::Find::name) if (-M $File::Find::name > $days && -f
$File::Find::name) },$dir;
but I prefer the first option. Why? ;-)
<waa...@my-deja.com> escribió en el mensaje de noticias
86l429$5l$1...@nnrp1.deja.com...
> Hi there,
>
> Can someone help me out ? I'm trying to write a script which deletes
> files in a certain directory on the server, that are older than let's
> say 30 day's. I just can't seem to get the code right... Is there
> anybody out there who has the lines available for me ?
>