Windows: SysUtils.FileGetDateTimeInfo returns false on existing files.
Summary
SysUtils.FileGetDateTimeInfo returns false on existing files.
(Tested on Windows only)
Issue noticed by forum user Big Hawk in this thread.
System Information
- Operating system: Win11 Home
- Processor architecture: x86_64 (32-bit fpc)
- Compiler version: 3.3.1-7446-ga755f38d2b
- Device: Computer
Steps to reproduce
Call FileGetDateTimeInfo on an existing file.
Example Project
program test;
{$mode objfpc}
{$h+}
uses
Windows, SysUtils;
var
B: Boolean;
DTinfo: TDateTimeInfoRec;
const
Fn = 'foo.bar'; //make sure this file exists
begin
writeln('FileExists(''',Fn,''')=',FileExists(Fn));
B := FileGetDateTimeInfo(Fn, DTinfo, False);
writeln('FileGetDateTimeInfo(''',Fn,''')=',B);
end.
What is the current bug behavior?
The example program outputs:
FileExists('foo.bar')=TRUE
FileGetDateTimeInfo('foo.bar')=FALSE
What is the expected (correct) behavior?
It should output:
FileExists('foo.bar')=TRUE
FileGetDateTimeInfo('foo.bar')=TRUE
Possible fixes
function FileGetDateTimeInfo(const FileName: string;
out DateTime: TDateTimeInfoRec; FollowLink: Boolean = True): Boolean;
var
Data: TWin32FindDataW;
FN: unicodestring;
begin
Result := False;
SetLastError(ERROR_SUCCESS);
FN:=FileName;
if Not GetFileAttributesExW(PWideChar(FileName), GetFileExInfoStandard, @Data) then <<FileName is AnsiChar
exit;
[snip]
Possible patch attached.