LucieLastic
Programmer
hi
I'd like to get the datetime of a given filename. I've tried this so far but keeps returning INVALID_HANDLE_VALUE:
I just wish to get the datetime of the file, I don't want to change any properties of the file.
Thanks in advance for help.
Many thanks,
Lou
I'd like to get the datetime of a given filename. I've tried this so far but keeps returning INVALID_HANDLE_VALUE:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var WriteTime : TFileTime;
FileDateTime : TDateTime;
hfile : Thandle;
Security : TSecurityAttributes;
pInputFile : array[0..MAX_PATH] of Char;
begin
mmResults.clear;
StrPCopy(pInputFile, edfile.text);
hFile := Createfile(
pInputFile,
GENERIC_READ,
FILE_SHARE_READ,// 0,
@Security,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if hfile = INVALID_HANDLE_VALUE then
begin
mmResults.lines.add('File not found - Invalid Handle Value');
end
else
begin
GetfileTime(hFile, nil, nil, @WriteTime);
FileDateTime := FileTime2DateTime(WriteTime);
mmResults.lines.add(FormatDateTime('dd mmm yyyy hh:nn:ss.mss', FileDatetime));
end;
end;
function TForm1.FileTimeToDAteTime(FileTime: TFileTime): TDateTime;
var
LocalFileTime: TFileTime;
SystemTime: TSystemTime;
begin
try
FileTimeToLocalFileTime(FileTime, LocalFileTime);
FileTimeToSystemTime(LocalFileTime, SystemTime);
Result := SystemTimeToDateTime(SystemTime);
except
on E: Exception do
showmessage('FileTimeToDAteTime : '+e.message + ' datetime - ' +datetimetostr(Result));
end;
end;
I just wish to get the datetime of the file, I don't want to change any properties of the file.
Thanks in advance for help.
Many thanks,
Lou