On Sunday 06 Jun 2010 19:59:36 Wojciech Łysiak wrote:
> On 06.06.2010 18:12, newbie01 perl wrote:
> > Hi all,
> > 
> > Oracle core dumps are created as directories. I want to remove these
> > directories after a certain period of time, for example 10 days.
> > 
> > I have the following script that searches a directory for files that are
> > older than 10 days and possibly remove them. At the moment, for the sake
> > of testing, am printing them out for the meantime.
> > 
> > While the code below seems to work, it also include the main directory as
> > well in the deletion, can someone advise how I can exclude that from the
> > deletion?
> 
> Hello there,
>    IMO you have to exclude '.' and '..' directories from the unlink loop.
> 
> Try something like this:
> 
> my $dir = '/raid/test';
> opendir(DIR,$dir) || die "Can't open $dir : $!\n";
> my @files = readdir(DIR);
> close(DIR);
> chdir $dir || die "$!\n";
> 
> foreach my $file(@files)
> {
>      #print "$dir/$file\n";
>       if ($file !~ /\.+/)

Don't do such a check. Use File::Spec->no_upwards() instead.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to