Search results for 'FileTimeToDateTime'. 1 post(s) found.
2009/08/19 14:46
How to get file created time, modified time, and last accessed time ?
2009/08/19 14:46 in Delphi

In order to get the File Attributes, you can get it by file search API.
Here's an example of how to show the creation, last access and last modification dates and times of a file:
uses SysUtils;
procedure TForm1.Button1Click(Sender: TObject);
var
SR: TSearchRec;
CreateDT, AccessDT, ModifyDT: TDateTime;
begin
if FindFirst('c:\test\text01.txt', faAnyFile, SR) = 0 then begin
CreateDT := FileTimeToDateTime(SR.FindData.ftCreationTime);
AccessDT := FileTimeToDateTime(SR.FindData.ftLastAccessTime);;
ModifyDT := FileTimeToDateTime(SR.FindData.ftLastWriteTime);;
ShowMessage('Created: ' + DateTimeToStr(CreateDT) +
' Accessed: ' + DateTimeToStr(AccessDT) +
' Modified: ' + DateTimeToStr(ModifyDT));
end
else
ShowMessage('Sorry, could not find the file');
FindClose(SR);
end;
In delphi 2009, you need to call FirndFirst functions as SysUtils.FindFirst. So you need to use as below way in Delphi 2009.
procedure TForm1.Button1Click(Sender: TObject);
var
SR: TSearchRec;
CreateDT, AccessDT, ModifyDT: TDateTime;
begin
if SysUtils.FindFirst('c:\test\text01.txt', faAnyFile, SR) = 0 then begin
CreateDT := FileTimeToDateTime(SR.FindData.ftCreationTime);
AccessDT := FileTimeToDateTime(SR.FindData.ftLastAccessTime);;
ModifyDT := FileTimeToDateTime(SR.FindData.ftLastWriteTime);;
ShowMessage('Created: ' + DateTimeToStr(CreateDT) +
' Accessed: ' + DateTimeToStr(AccessDT) +
' Modified: ' + DateTimeToStr(ModifyDT));
end
else
ShowMessage('Sorry, could not find the file');
FindClose(SR);
end;
In addition, if your delphi does not support FileTimeToDateTime function use below function.function FileTimeToDateTime( FileTime : TFileTime ) : TDateTime;
var
ModifiedTime : TFileTime;
SystemTime : TSystemTime;
begin
try
FileTimeToLocalFileTime( FileTime, ModifiedTime );
FileTimeToSystemTime( ModifiedTime, SystemTime );
Result := SystemTimeToDateTime( SystemTime );
except
Result := Now;
end;
end;
Another posts included in "Delphi"
| How to read/wrtie INI file in Delphi ? (0) | 2009/08/21 |
| Delphi Pointer Types (0) | 2009/08/22 |
| Get the length of arrays and a string (0) | 2009/08/22 |
| Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (0) | 2009/07/20 |
| When subject is crashing in TIdSMTP VCL (0) | 2009/07/20 |
| How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL (0) | 2009/07/20 |
| How to encode subject content when sending mail with TIdMessage ? (0) | 2009/07/16 |
| Base64 Encoding/Decoding function for Delphi (0) | 2009/07/16 |
Prev

Rss Feed