Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to delete a file ?

0 views
Skip to first unread message

waa...@my-deja.com

unread,
Jan 25, 2000, 3:00:00 AM1/25/00
to
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 ?

Thanks in advance


Sent via Deja.com http://www.deja.com/
Before you buy.

Joe Smith

unread,
Jan 26, 2000, 3:00:00 AM1/26/00
to
In article <86l429$5l$1...@nnrp1.deja.com>, <waa...@my-deja.com> wrote:
>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 ?

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"

G Caraballo

unread,
Jan 28, 2000, 3:00:00 AM1/28/00
to
You can try:


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 ?
>

0 new messages