Solved

last access time

Posted on 1997-12-01
3
171 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 265
FMX enumerated colours 2 99
When I am typing into a TEdit last word repeats 7 133
How to renew a Delphi rad-studio licence? 5 64
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

770 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