-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.pas
49 lines (40 loc) · 1.2 KB
/
Utils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
unit Utils;
interface
uses Windows;
const
KB2Bytes = 1024;
function FormatFileSize(Size : Int64) : string;
function FormatFileTimeLong(FTime : TFileTime) : string;
implementation
uses SysUtils;
function FormatFileSize(Size : Int64) : string;
var
Bytes, KB : Double;
begin
Bytes := Size; KB := Bytes/KB2Bytes;
if KB >= 1024 then
Result := Format('%.2n MB (%.0n bytes)', [KB/1024, Bytes])
else
if Bytes > 1024 then
Result := Format('%.1n KB (%.0n bytes)', [KB, Bytes])
else
Result := Format('%.0n bytes', [Bytes]);
end;
{ Formats a file date/time to a string using the long date/time format }
function FormatFileTimeLong(FTime : TFileTime) : string;
var
LocalFileTime : TFileTime;
STime : TSystemTime;
D : TDateTime;
Hour, Min, Sec, MSec: Word;
begin
FileTimeToLocalFileTime(FTime, LocalFileTime);
FileTimeToSystemTime(LocalFileTime, STime);
D := SystemTimeToDateTime(STime);
DecodeTime(D, Hour, Min, Sec, MSec);
if (Hour <> 0) or (Min <> 0) or (Sec <> 0) or (MSec <> 0) then
Result := FormatDateTime('dddd, mmmm d, yyyy hh:mm:ss AM/PM', D)
else
Result := FormatDateTime('dddd, mmmm d, yyyy', D);
end;
end.