Solved

last access time

Posted on 1997-12-01
3
167 Views
Last Modified: 2011-04-14
Here's a very simple question...
how do I get the last access time of a file

I know that to get the last write time it's:
Fsearchrec.finddata.ftlastwritetime

But I don't have my reference book with me and I would appreciate it if someone could tell me what last access time is for Tsearchrec

Tsearchrec.findata.????

Thanks
0
Comment
Question by:rafy
  • 2
3 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1352626
Hi

The following routine shows the create, access and write times of autoexec.bat.  It uses a routine called "FileTimeToDateTime" which I have included below.

procedure TForm1.Button1Click(Sender: TObject);
var
    fs: TFileStream;
    ftCreate, ftAccess, ftWrite: TFileTime;
    dtCreate, dtAccess, dtWrite: TDateTime;
begin
    fs := TFileStream.Create('C:\AutoExec.bat', fmOpenRead or fmShareDenyNone);
    try
        GetFileTime(fs.Handle, @ftCreate, @ftAccess, @ftWrite);

        dtCreate := FileTimeToDateTime(ftCreate);
        dtAccess := FileTimeToDateTime(ftAccess);
        dtWrite := FileTimeToDateTime(ftWrite);

        ShowMessage('Create: ' + DateTimeToStr(dtCreate));
        ShowMessage('Access: ' + DateTimeToStr(dtAccess));
        ShowMessage('Write: ' + DateTimeToStr(dtWrite));
    finally
        fs.Free;
    end;
end;

function FileTimeToDateTime(AFileTime: TFileTime): TDateTime;
var
    FatDate, FatTime: Word;
    ADay, AMonth, AYear, ASec, AMin, AHour: Word;
begin
    FileTimeToDOSDateTime(AFileTime, FatDate, FatTime);
    ADay := (FatDate and 31);
    AMonth := (FatDate and 480) shr 5;
    AYear := ((FatDate and 65024) shr 9) + 1980;
    ASec := (FatTime and 31) * 2;
    AMin := (FatTime and 2016) shr 5;
    AHour := ((FatTime and 63488) shr 11);
    Result := EncodeDate(AYear, AMonth, ADay) + EncodeTime(AHour, AMin, ASec, 0);
end;

Regards,
JB
0
 

Author Comment

by:rafy
ID: 1352627
Thanks, but I already have my code written up using the windows Tsearchrec Data type, all I want is the field for last access time....it's an old program that I want to modify, not one I want to rewrite

It's probably something like Tsearchrec.finddata.ftlastaccess??

all I need is the last part...Thanks again
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1352628
Sorry, I misunderstood you.

Yes, TSearchRec's FindData has (inter alia) ftCreationTime, ftLastAccessTime and ftLastWriteTime.

JB
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now