Solved

last access time

Posted on 1997-12-01
3
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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