Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File date...

Status
Not open for further replies.

Aljosa

Programmer
Dec 3, 2007
1
SI
Hi,

It is possible to check file's creation date not only Change/Modify date.

Thanks
 
Is this a question?

Yes, it is possible to find a file's creation date/time, last write date/time and last access date/time.

Something like this should work:
Code:
function FormatFileTime(const mask: string; FileTime: TFileTime): string;
var
  ModifiedTime: TFileTime;
  SystemTime: TSystemTime;
begin
  Result := '';
  if (FileTime.dwLowDateTime = 0) and (FileTime.dwHighDateTime = 0) then
    Exit;
  try
    FileTimeToLocalFileTime(FileTime, ModifiedTime);
    FileTimeToSystemTime(ModifiedTime, SystemTime);
    Result := FormatDateTime( mask, SystemTimeToDateTime(SystemTime) );
  except
    Result := FormatDateTime( mask, Now );  // Something to return in case of error
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  Mask = 'yyyy-mm-dd hh-nn-ss';
var
  lpFindFileData: TWIN32FindData;
begin
  FindFirstFile( pchar('c:\test.txt'), lpFindFileData );
  Edit1.Text := FormatFileTime( mask, lpFindFileData.ftCreationTime );
  Edit2.Text := FormatFileTime( mask, lpFindFileData.ftLastAccessTime );
  Edit3.Text := FormatFileTime( mask, lpFindFileData.ftLastWriteTime );
end;

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top