Dropping files on form creates short file names
lazarus / 34-Windows
----------------------------------------------------------------------
rpetges · 2023-10-07 14:31
Hi all,
I have s strange behaviour in Windows when dropping files from
Explorer on a form. In the OnDropFiles event, the array of strings
returns short filenames when the dropped files are over MAX-PATH
length.
To demonstrate, I added a small test application and a folder
structure. Extract the ZIP with the folder structure in your Documents
folder. You will find two small files, each per directory. Try to drop
them on the application and you'll see the following :
If the full path goes beyond MAX-PATH, then the string returned by the
array will be shortened to
C:\Users\Support\Documents\TESTFO~2\SUBFOL~1\2022-0~1.ODT
I did my tests with Win11. To extract the ZIP file for the test files,
please use 7-Zip as Windows ZIP tool does not work with these long
files
Any idea on how to get the full path names ?
Best regards,
Romain
----------------------------------------------------------------------
Josh · 2023-10-07 15:43
windows i think still defaults to a max file path of 260.
you can turn on long file paths
check out
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-
path-limitation?tabs=registry
----------------------------------------------------------------------
rpetges · 2023-10-07 15:53
I already played around with this setting and embedded the XML
manifest into the application after posting the question:
true
But it has no impact, the application still retrieves short names.
Windows drives my crazy
----------------------------------------------------------------------
Josh · 2023-10-07 16:11
does thiswork?
Code: [Select]
true
----------------------------------------------------------------------
rpetges · 2023-10-07 16:20
Nope, does not work.
----------------------------------------------------------------------
ASerge · 2023-10-07 17:24
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i uses
jwaWinBase; function FileNameAsLongName(const AFileName: string):
string;var U, Buf: UnicodeString; Len: DWORD;begin if not
FileExists(AFileName) then Exit(AFileName); U :=
UTF8Decode(AFileName); Len := GetLongPathNameW(Pointer(U), nil, 0);
SetString(Buf, nil, Len - 1); GetLongPathNameW(Pointer(U),
Pointer(Buf), Len); Result := UTF8Encode(Buf);end; procedure
TForm1.FormDropFiles(Sender: TObject; const FileNames: array of
string);begin Memo1.Text:= FileNames[0]; Memo1.Append(LineEnding);
Memo1.Append(FileNameAsLongName(FileNames[0]));end;
----------------------------------------------------------------------
rpetges · 2023-10-07 18:28
Many thanks ASerge .... it works