Windows API and long paths lazarus / 34-Windows ---------------------------------------------------------------------- konikula · 2023-07-18 11:15 Function to get file attributes and dates: 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  Function GetFileDates(fileName:String; var c: FileTime; var m: FileTime; var a: FileTime; var attr: DWord):Boolean; var info:_WIN32_FILE_ATTRIBUTE_DATA; begin   if GetFileAttributesEx(PChar(fileName),GetFileExInfoStandard,@info) then begin     c:=info.ftCreationTime;     m:=info.ftLastWriteTime;     a:=info.ftLastAccessTime;     attr:=info.dwFileAttributes;     Result:=True;   end else Result:=False; end;   I have this function. It works fine on Windows XP, but on Windows 11 it requires fileName to be converted to short path (from long file names to 8.3 format). Am I doing something wrong, or converting paths is inevitable? I also tried Manifest / Long path awarness, but with no effect.. ---------------------------------------------------------------------- marcov · 2023-07-18 11:46 Is the path _exactly_ the same? Sounds like the Windows path is a bit longer on Win11 than XP (due to the virtual folders?). If you use -W functions and prefix _expanded paths_ with \\?\  you can use a bit more characters, but it is tricky. Easier is to turn on the manifest options, but those are Windows 10 1805 or 1905 and higher only. ( https://learn.microsoft.com/en-us/troubleshoot/windows- server/deployment/filenames-with-spaces-require-quotation-mark and https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file ) ---------------------------------------------------------------------- Chusik · 2023-07-18 12:19 I guess you have a problem with Unicode file names, try this code instead: 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 Function GetFileDates(fileName:String; var c: FileTime; var m: FileTime; var a: FileTime; var attr: DWord):Boolean;var  info: TWin32FindDataW;begin  if GetFileAttributesExW(PWideChar(UTF8Decode(fileName)),GetFileExInfoS tandard,@info) then begin    c:=info.ftCreationTime;    m:=info.ftLastWriteTime;    a:=info.ftLastAccessTime;    attr:=info.dwFileAttributes;    Result:=True;  end else Result:=False;end; if path is really very long then you can use code like this: 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 Function GetFileDates(fileName:String; var c: FileTime; var m: FileTime; var a: FileTime; var attr: DWord):Boolean;var  info: TWin32FindDataW;begin  if GetFileAttributesExW(PWideChar('\\?\' + UTF8Decode(fileName)),GetFileExInfoStandard,@info) then begin    c:=info.ftCreationTime;    m:=info.ftLastWriteTime;    a:=info.ftLastAccessTime;    attr:=info.dwFileAttributes;    Result:=True;  end else Result:=False;end; ---------------------------------------------------------------------- rvk · 2023-07-18 14:42 Quote from: konikula on July 18, 2023, 01:15:08 pm... but on Windows 11 it requires fileName to be converted to short path (from long file names to 8.3 format).Definitely don't do that. You shouldn't depend on the 8dot3 notation. Not all (ntfs) filesystems have those enabled. (or at least the can be deactivated per volume) What's the length of fileName? ---------------------------------------------------------------------- KodeZwerg · 2023-07-18 15:02 Feel free to watch how I do it on Windows machines. Code you find here. ---------------------------------------------------------------------- konikula · 2023-07-20 07:40 Chusik solution solved this problem I think. This works well on Windows XP and on Windows 11: 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 Function GetFileDates(fileName:String; var c: FileTime; var m: FileTime; var a: FileTime; var attr: DWord):Boolean;var  info: TWin32FindDataW;begin  if GetFileAttributesExW(PWideChar(UTF8Decode(fileName)),GetFileExInfoS tandard,@info) then begin    c:=info.ftCreationTime;    m:=info.ftLastWriteTime;    a:=info.ftLastAccessTime;    attr:=info.dwFileAttributes;    Result:=True;  end else Result:=False;end; Thank you all for your help. Best regards, Matt