Per the docs:

*The method form returns True on success, or fails with X::IO::Unlink if
the operation could not be completed. If the file to be deleted does not
exist, the routine treats it as success.*

So I'm assuming that your occasional failures might have been if something
had the file open at the time you were trying to unlink it.

When it fails, whatever the OS error was is in the Exception object, so you
can introspect it and see what the complaint was.

Note - you do not have to check to see if the file exists before you remove
it. As long as the file isn't there, that's a success. You only need to
check that if specifically care if it existed first.


On Thu, Oct 9, 2025 at 5:25 PM ToddAndMargo via perl6-users <
[email protected]> wrote:

> On 10/9/25 7:44 AM, Tom Browder wrote:
> >     if not unlink $OldFileName {
> >             PrintRedErr( "Unable to Delete OldFileName <$OldFileName>\n"
> );
> >          }
> >
> >
> > Todd, what is your intent? Do want to delete an existing? Or not?
>
> Hi Tom,
>
> I want to delete an existing file.
>
> This is a file download program that checks for new revisions
> of software I support and copies to a special flash drive with
> a read only switch, so it does not pick up or spread viruses.
> If it finds a new version, it downloads it and removes the
> old version.
>
> In this particular sub, the new version is tested to see if
> it is the predicted size.  If so, it deletes the old version
> of that file.  If the size test file fails, it alerts and removes
> that bad new file (303 not found, etc.) and leaves the
> old file alone.
>
> I was presuming that unlink returned a true or false.  True
> if delete was successful and false if not.  The results
> were random.  (It mostly worked.)
>
> -T
>

Reply via email to