Hi Dan.

Dan Muey wrote:
> Howdy list,
>
> Is there a better way to tell if a file exists than
> $ftp->size() being greater than zero
> Or
> $ftp->ls()
>
> Also if I delete a file with $ftp->delete($file);
> It will return 1 on success but if it returns 0 how can I
> tell if it's because it didn't exist and therefore could not be
> deleted or it existed but couldn't
> be deleted for some reason (permissions. Etc..)
> The best way I came up with is to do a size() before if size
> returns 0 it may not exist or is zero in size. But then that takes
> you back to question 1. Ahhh I'm going in circles!!!
>
> What I'd like to do is simply:
> (WHERE exists() is hopefully a solution to my first question)
>
>  if($ftp->exists($file)) {
> $ftp->delete($file);
> if($ftp->exists($file)) { print "Could not delete $file"; }
> else { print "$file is all gone"; }
>  } else { print "$file does not exist so I did not even try to
> delete it" }

'size' is the way to do it, but remember that it will return
zero for a file of zero size. What you need is 'defined'.

This little subroutine will fulfil your wishes and make the
code above work.

  sub Net::FTP::exists {
    my $ftp = shift;
    defined $ftp->size(@_);
  }

HTH,

Rob




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

Reply via email to