This is how i use the unlink. Please take a look.
Thanks.
-----------

#!/usr/bin/perl 
# clean old file

use Carp;

$cur_time = time;   # current time in epoch (in
seconds)
$dir = '/opt/sybase/OCT/dump/';
$hour = 10 ;

opendir DIR, $dir || die "Failed to open $dir: $!";

my @files = readdir DIR;
closedir DIR;
unless ($cnt = @files) {
 print "No file to rm.\n";
 return;
}

foreach $file (@files) {
        next if $file =~ /\./;

        ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
$size, $atime, $mtime, $ctime, $blksize, $blocks) =
stat $file;

        $fage = ($cur_time - $mtime) / 3600; # file in
hours (note: 1 hr = 3600 sec)

        print "file found: $file ($fage hr)\n";

        if ($fage > $hour) {
                printf "\nDelete file older than $hour
hrs : %4s  %.2f hrs old\n", "$dir"."$file",$fage;
                $rc = unlink "$dir"."$file" ;
                $stat = $rc ? "success" : "failed";
                print "\t$file remove status:
$stat.\n";
        } 
        else {
                printf "Too young: %15s [%.2f hr]\n",
$file, $fage;
        }
}
        opendir DIR, $dir || die "Failed to open $dir:
$!";
        my @files = readdir DIR;
        $cnt2 = @files;

        print  "\nTo remove all files that are older
than $hour in directory: $dir\n";
        printf "Before delete: %5d\n", $cnt;
        printf "Files deleted: %5d\n", $cnt - $cnt2;
        printf "After delete : %5d\n", $cnt2;
        closedir DIR;

        
--- drieux <[EMAIL PROTECTED]> wrote:
> 
> On Friday, April 5, 2002, at 05:14 , loan tran
> wrote:
> [..]
> > I want to remove *.tar and *.Z file too.
> >
> > Any suggestions?
> 
> how were you building your list of files to be
> removed?
> 
> i just built both *.tar and *.Z files and was able
> to
> remove them with a perl script using the methods
> listed
> in
> 
>       perldoc -f unlink
> 
> 
> 
> ciao
> drieux
> 
> ---
> 
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to