Hi All,partitionKey=%28https%2Cbid13.com%29\cache\morgue\114\{7cccd5e9-a7aa-4349-a2e9-569baf007272}.final] );"
When you are trying to delete a a file
that has a very long file & path name ,
from the cmd line, powershell, your unlink
command within your compiler, and it just
wont delete. And you get the following
the returned error message of
"File not found"
And no you did not misspell it it.
But you can delete it with Windows
Explorer, here is what is going on.
Windows has two maximum file & path names
character lengths.
The default is called "MAX_PATH" and it is
260 characters long. Del and friends
makes an API (Application Program Interface)
call to DeleteFileA (UTF8) or DeleteFileW
(UTF16). The call lops off the extra
characters above MAX_PATH, so you
are trying to delete a different file name,
which is why the File Not Found error.
The solution is to use the other maximum,
non-default path limit of 32,767 characters.
To do this, prepend \\?\ to your path/file name.
Windows Explorer does this automatically
for you which is why it works. You can also
prepend this to shorter files without issue
(it is probably shower though.)
Some examples from the Raku (Perl6) module
I wrote to handle this. It returns OK if
the file got deleted or the error message
if not:
The Q[...] means a direct quote.("" does not work
so when used from the command line with Raku.)
Current directory path:
echo abc > eraseme.txt && raku -I. -e "use NativeDelete :ApiDeleteFile; say ApiDeleteFile( Q[eraseme.txt] )" && type eraseme.txt
OK
The system cannot find the file specified.
Looking for the wrong file:
echo abc > eraseme.txt && raku -I. -e "use NativeDelete :ApiDeleteFile; say ApiDeleteFile( Q[eraseme2.txt] )" && type eraseme.txt
The system cannot find the file specified.
abc
Long path from hell:
raku -I. -e "use NativeDelete :ApiDeleteFile; say ApiDeleteFile( Q[\\?\D:\MyDocsBackup\backup2\Mozilla 2024-04-15 21;14;31 (Full)\Firefox\Profiles\pj0elosu.default-release\storage\default\https+++505991220932649.webpush.freshchat.com^
OK
HTH,
-T
On 4/21/2024 11:16 PM, T wrote:
Hi All,
Microsoft has created filenames in C: (in a couple of areas related to products
you might pay for), where the character set was "unrepresentable". Attempting >to type or paste the wacky symbols simply will not work.
But some manager at
MS must have given the Intern a kick in the bum for that, and the obnoxious structure
disappeared. It might have been considered to be an "exotic namespace". I think
CleanMgr could remove it, but you couldn't actually tell it to remove a specific
item, and only certain situations made removal possible ("Windows.old").
The "Length Bug" was removed some time ago.
I could arrange a file to have
a certain length ("260"), it could not be removed in File Explorer, but a Perl rename()
could shorten the name enough to allow regular deletion.
At a later point,
that rough spot was removed.
Paul
On Mon, 22 Apr 2024 00:51:12 -0400, Paul <nospam@needed.invalid>
wrote:
The "Length Bug" was removed some time ago.
Really? It's still there in Win-7, though I probably shouldn't be
surprised at this as Win-7 is obsolete.
I tried to move stuff from my MBP to archive on an external drive
hanging off of my Win-7 box but the Windows OS complained that some of
the files had names that were too long. Possibly due to the tree
length of the paths.
There's far too many files to manually shorten the paths and names so
it needs to be an automatic magical solution. One thing I could do is
to drain the lower branches of the tree into upper ones and so shorten
the path-names but I don't know whether that would work on the Win-7
box.
At a later point,
that rough spot was removed.
In Win-10 and 11 I suppose?
I almost never temp move individual files, preferring instead to move entire >folders and their subfolders and files. That way, it's easy to put things back >where they belong afterwards.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 361 |
Nodes: | 16 (2 / 14) |
Uptime: | 123:30:26 |
Calls: | 7,716 |
Files: | 12,861 |
Messages: | 5,727,956 |