Solved

last access time

Posted on 1997-12-01
3
166 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I misunderstood you.

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

JB
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

14 Experts available now in Live!

Get 1:1 Help Now