Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-01

Deleting 'Nonexistent' files under windows

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rolf Grunsky

Is it possible to access files that have path lengths too long to access from explorer through Windows API from Pascal?

I keep ending up with these very long file names which then I can not access. It seems that Windows will create the files, usually by copying the files from another source but the resulting path is too long to access the file or to delete it. Using the "\\?\" trick doesn't always work. I really don't want to spend $40 on a program just to delete some files. If I get really desperate I can always pull the drive from the Windows machine and connect it to the Linux machine but that's starting to look like work. A simple command line program would be much easier.

Rolf

TRUTH in her dress finds facts too tight. In fiction she moves with ease. Stray Birds by Rabindranath Tagore

Reply by email

Sven Barth
to Rolf Grunsky
"Rolf Grunsky" wrote
Is it possible to access files that have path lengths too long to access

from explorer through Windows API from Pascal?

I keep ending up with these very long file names which then I can not

access. It seems that Windows will create the files, usually by copying the files from another source but the resulting path is too long to access the file or to delete it. Using the "\\?\" trick doesn't always work. I really don't want to spend $40 on a program just to delete some files. If I get really desperate I can always pull the drive from the Windows machine and connect it to the Linux machine but that's starting to look like work. A simple command line program would be much easier.

While in my opinion the Pascal function should work with the "\\?\" notation (if not, that's a bug) you can always use the corresponding Windows API function directly (AFAIK DeleteFileW).

Regards,
Sven

Reply by email

Marco van de Voort
to Rolf Grunsky: Is it possible to access files that have path lengths too long to access from explorer…

In our previous episode, Rolf Grunsky said:

Show quoted text 8 lines
Is it possible to access files that have path lengths too long to access from explorer through Windows API from Pascal? I keep ending up with these very long file names which then I can not access. It seems that Windows will create the files, usually by copying the files from another source but the resulting path is too long to access the file or to delete it. Using the "\\?\" trick doesn't always work.

One must also call the unicode api to make that trick work. FPC only does that since 3.0.

Reply by email

Bart
to Rolf Grunsky: Is it possible to access files that have path lengths too long to access from explorer…
Rolf Grunsky wrote
I keep ending up with these very long file names which then I can not access.

Been there.
I once created a folder and file using W API and \?\\ syntax for testing purposes.
This all went well, but Windows did not like it and would not let me remove the file and folder.
I rewote my test program to remove them, but still Windows refused. (The folder name ended in a space, you could not even browse to the folder in Windows Explorer)

I then booted a live Linux distribution and removed it from there. No problem whatsoever.

Bart

Reply by email

Jürgen Hestermann
to Bart
Bart wrote 6 lines
I once created a folder and file using W API and \?\\ syntax for testing purposes. This all went well, but Windows did not like it and would not let me remove the file and folder. I rewote my test program to remove them, but still Windows refused. (The folder name ended in a space, you could not even browse to the folder in Windows Explorer)

I have written a file manager which uses the (Unicode) Windows API with \?\\ syntax and I never had any problems deleting long paths (testet up to 35,000 characters) or such which have whitespace somewhere.

Of course, you have to make sure, that whitespace is not removed by some other functions before you use the name and you also need to make sure that UTF-16 is used for the API function.

Reply by email

Jürgen Hestermann
to Jürgen Hestermann
Jürgen Hestermann wrote
I have written a file manager which uses the (Unicode) Windows API with \?\\ syntax and I never had any problems deleting long paths (testet up to 35,000 characters)

Sorry, the number of tested characters wasn't 35,000 but about 25,000. Still enough to make sure it works in general.

Reply by email