2004. augusztus 29., vasárnap

Get the time stamp of a directory


Problem/Question/Abstract:

How to get the time stamp of a directory

Answer:

Solve 1:

program Project1;

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

function GetTimeStamp(Directory: string): TDateTime;
var
  Search: TSearchRec;
begin
  Result := 0;
  if FindFirst(Directory + '.', faDirectory, Search) = 0 then
  begin
    Result := FileDateToDateTime(Search.Time);
  end
  else
    MessageDlg('Directory doesnt exist', mtWarning, [mbOK], 0);
  FindClose(Search);
end;

begin
  MessageDlg('Folder Create Date: ' + DateTimeToStr(GetTimeStamp('c:\temp\')),
    mtWarning, [mbOK], 0);
end.


Solve 2:

function FileTimeToDateTime(FileTime: TFileTime): TDateTime;
var
  LocalFileTime: TFileTime;
  SystemTime: TSystemTime;
begin
  FileTimeToLocalFileTime(FileTime, LocalFileTime);
  FileTimeToSystemTime(LocalFileTime, SystemTime);
  Result := SystemTimeToDateTime(SystemTime);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  FSearchRec: TSearchRec;
  DirDate: TDateTime;
begin
  FindFirst('C:\Temp', faDirectory, FSearchRec);
  DirDate := FileTimeToDateTime(FSearchRec.FindData.ftCreationTime);
  ShowMessage(DateTimeToStr(DirDate));
end;

Nincsenek megjegyzések:

Megjegyzés küldése