Forum > General

TSearchRec Date Time

(1/2) > >>

xinyiman:
I'm probing the C with the following code and I want to know how to get the dates of each file, date created, date last modified and access date. A solution that will work on both Windows and Linux. Thanks

My code:


procedure TForm1.Button1Click(Sender: TObject);
var
  Info : TSearchRec;
  Count : Longint;
  app: string;
  DT: TTimeStamp;
  DataCreazione, DataUltimoAccesso, DataUltimaModifica: DWord;
begin
     Count:=0;
     //se volessi leggere la cartella corrente basterebbe *
     If FindFirst ('c:\*',faAnyFile and faDirectory,Info)=0 then
       begin
       Repeat
         Inc(Count);
         With Info do
           begin
           If (Attr and faDirectory) = faDirectory then
           begin
             Form1.Lista_File.Items.Add('Dir : ' + Name + ' dimensione: ' + IntToStr(Size));
           end
           else
           begin
                DT:=MSecsToTimeStamp(Info.FindData.ftCreationTime.dwLowDateTime);
                Form1.Lista_File.Items.Add('File : ' + Name + ' dimensione: ' + IntToStr(Size) + '-->' + IntToStr(DT.Date));
           end;
         end;
       Until FindNext(info)<>0;
       end;
     FindClose(Info);
     //Writeln ('Finished search. Found ',Count,' matches');
     Form1.Lista_File.Items.Add('Finished search. Found ' + IntToStr(Count) + ' matches');
end;

xenblaise:
try that :D

--- Quote ---function FileTimeToDTime(FTime: TFileTime): TDateTime;
var
  LocalFTime: TFileTime;
  STime: TSystemTime;
begin
  FileTimeToLocalFileTime(FTime, LocalFTime);
  FileTimeToSystemTime(LocalFTime, STime);
  Result := SystemTimeToDateTime(STime);
end;

function aboutfile(f:string):string;
var
  SR: TSearchRec;
  CreateDT, AccessDT, ModifyDT: TDateTime;
  Size: Integer;
begin
  if FindFirst(f, faAnyFile, SR) = 0 then begin
    CreateDT := FileTimeToDTime(SR.FindData.ftCreationTime);
    AccessDT := FileTimeToDTime(SR.FindData.ftLastAccessTime);;
    ModifyDT := FileTimeToDTime(SR.FindData.ftLastWriteTime);;
    Size := SR.Size;
    Result := ('Created: ' + DateTimeToStr(CreateDT) +
      '  and Accessed: ' + DateTimeToStr(AccessDT) +
      '  and Modified: ' + DateTimeToStr(ModifyDT) +
      '  and Size: ' + IntToStr(Size));
  end
  else
    Result := 'No information';
    FindClose(SR);
end;

--- End quote ---

xinyiman:
unit1.pas(23,47) Error: Identifier not found "TFileTime"

Why?

xinyiman:
The solution in

uses windows

but is not cross platform solution!  %)

Help me please

xenblaise:
try this instead

--- Quote ---var fecha:Tdate;fechatmp:longint;filename:string;
fechatmp:=FileAge(filename);
fecha:=int(FileDateToDateTime(fechatmp))

--- End quote ---

or


--- Quote ---var
TFiletime: TDatetime;
TFiletime := Encodedate(myear, mmonth, mday)
    + EncodeTime(mHours, mminutes, mseconds, 0);

--- End quote ---


since there is no File creation time in unix :D

Navigation

[0] Message Index

[#] Next page

Go to full version