On 4/17/24 05:50, yary wrote:
What does the windows native delete do which you need, that raku's unlink doesn't have?

without unlink $FileName { say "Could not delete $FileName:", .exception.message };

-y

Hi Yary,

This is Windows we are dealing with.  It is a kluge.
I have had unlink fail and could not figure out why.

DeleteFileA has wonderful error reporting, well
for Windows.  And you can always count on it doing
things right.  Well, again, maybe..

What caused me to do all this was my inability to delete
the following from the command shell, powershell, and
(Raku) unlink.  But I could delete from Windows Explorer.
I kept getting told the command could not find
the file.   AAAAHHHHH!!!!!

D:\MyDocsBackup\backup2\Mozilla 2024-03-26 16;10;20 (Full)\Firefox\Profiles\pj0elosu.default-release\storage\default\https+++505991220932649.webpush.freshchat.com^partitionKey=%%28https%%2Cbid13.com%%29\cache\morgue\114\{7cccd5e9-a7aa-4349-a2e9-569baf007272}.final

I had originally thought that the issue was the "weird" characters.
All my attempts to escape the failed.  So out of desperation,
I switched to DeleteFileA.

On DeleteFileA's web page was the give away:

    'Tip  Starting with Windows 10, Version 1607, you can
    opt-in to remove the MAX_PATH limitation without
    prepending "\\?\"'

And I did not realize this a first, but a thorough reading
of the web page and I finally understood.  The file I
was trying to delete was 265 characters long and the
limit (MAX_PATH) was 260.  The commands I was trying
were lopping off five of the characters.  And the commands
did not tell me I had exceeded MAX_PATH.  (This is M$ we
are dealing with after all.)

Now you all that live sheltered lives with Linux, this would
not be an issue.  But the kluge, it is.  You can have to
different max lengths and you have to know when and when
not to prepend.  I am sorry, but what poor programming
on M$'s part.  (Prepending works on shorter files, but
takes longer to process and sometimes coughs.)

You will notice my modules a few things:

1) if the length of the path/name exceeds MAX_PATH and the
path/name does not include \\?\`, then I prepend it.

2) if DeleteFileA return pass, I send back "OK" in the
string.  If not, I send back the error message from
Kernel32::GetLastError" (returns a number) and
Kernel32::WinFormatMessage (translates the error
number to text).

So now I have a powerful tool in addition to unlink in my
tool box to cope with the kluge.

In Linux, I will use unlink, but in the kluge, I will probably
use my ApiDeleteFile.

It never hurts to have enough tools.

-T

Me wonders why Windows programmers do not tear
all their hair out.


Reply via email to