Link to home
Start Free TrialLog in
Avatar of Ed Covney
Ed CovneyFlag for United States of America

asked on

Delphi FileTime

I can get the times (create, Access, Modifiy) of one file and change a second file's datetimes accordingly.  However, I'm having a devil of a time displaying that datetime as a string. See below.

 
FHIn  := FileOpen(FNOut,fmShareDenyWrite or fmOpenWrite);    
GetFileTime(FHIn,@FCDo,@FADo,@FMDo);
FileClose(FHIn);
FHOut := FileOpen(FNOut,fmShareDenyWrite or fmOpenWrite);    
SetFileTime(FHOut,@FCDo,@FADo,@FMDo);
FileClose(FHOut);
                               // - all working so far

showmessage(FormatDateTime('yyyy/mm/dd hh:mm:ss',FMDo)+'   '+FNOut)
                               // this displays - 1899/12/30 00:00:00  (and the file name)

What is the most direct way to display a file's date in string format?

TIA - Ed
Avatar of Ed Covney
Ed Covney
Flag of United States of America image

ASKER

Ooops - first code line shoud read:

FHIn  := FileOpen(FNIn,fmShareDenyWrite or fmOpenWrite);
ASKER CERTIFIED SOLUTION
Avatar of Thommy
Thommy
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Check function  DSiGetFileTimes(const fileName: string; var creationTime, lastAccessTime,   lastModificationTime: TDateTime): boolean from below url to get all file dates...

How to get create/last modified dates of a file in Delphi?

Use DateToStr to convert TDateTime values into string values...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rinfo - thanks for trying, but "FileTimeToSystemTime(F1_lastWrite,SysTimeStruct)"
produces an error (Delphi XE2):
      "E2250 There is no overloaded version of 'FileTimeToSystemTime' that
        can be called with these arguments"

which I've seen a lot of lately through all my trials  . . .
Thommy -

Thank you !!  Who would of thought of fileage? You, of course! I'll certainly add that to my bag 'o tricks.

Although it only produces dates (no times). I checked out "fileage" (Delphi Help) which in turn led me to a slight mod of your code (to enable times):

         FHInt := FileAge(FNIn);    
         FInDateTime := FileDateToDateTime(FHInt);
         strDIn := DateTimeToStr(FInDateTime );
         showmessage(strDIn);

File  datetimes    vs   system datetimes   vs local times, etal; confuses me to no end. So I'll certainly check out you link.

Thanks again - Ed