Author: Jonas Bilinkevicius
How to get the time stamp of a directory
Answer:
Solve 1:
1 program Project1;
2
3 uses
4 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
5
6 function GetTimeStamp(Directory: string): TDateTime;
7 var
8 Search: TSearchRec;
9 begin
10 Result := 0;
11 if FindFirst(Directory + '.', faDirectory, Search) = 0 then
12 begin
13 Result := FileDateToDateTime(Search.Time);
14 end
15 else
16 MessageDlg('Directory doesnt exist', mtWarning, [mbOK], 0);
17 FindClose(Search);
18 end;
19
20 begin
21 MessageDlg('Folder Create Date: ' + DateTimeToStr(GetTimeStamp('c:\temp\')),
22 mtWarning, [mbOK], 0);
23 end.
Solve 2:
24 function FileTimeToDateTime(FileTime: TFileTime): TDateTime;
25 var
26 LocalFileTime: TFileTime;
27 SystemTime: TSystemTime;
28 begin
29 FileTimeToLocalFileTime(FileTime, LocalFileTime);
30 FileTimeToSystemTime(LocalFileTime, SystemTime);
31 Result := SystemTimeToDateTime(SystemTime);
32 end;
33
34 procedure TForm1.Button1Click(Sender: TObject);
35 var
36 FSearchRec: TSearchRec;
37 DirDate: TDateTime;
38 begin
39 FindFirst('C:\Temp', faDirectory, FSearchRec);
40 DirDate := FileTimeToDateTime(FSearchRec.FindData.ftCreationTime);
41 ShowMessage(DateTimeToStr(DirDate));
42 end;
|