Registriert seit: 4. Dez 2012
Ort: Augsburg, Bayern, Süddeutschland
419 Beiträge
Delphi XE4 Ultimate
|
AW: Folder creation datetime
27. Mär 2013, 03:37
Hi,
maybe the following code could be some help for you - feel free to use it, if you like
Delphi-Quellcode:
type
TFileTime = (ftAccess, ftCreated, ftWrite);
function GetFileDateTime ( const Filename : string; const Filetime : TFileTime) : TDateTime;
var
f : TSearchRec;
t : _FILETIME;
s : _SYSTEMTIME;
d : Integer;
function GetTimeDiff : Integer;
var
t0, t1 : _SYSTEMTIME;
begin
GetLocalTime (t0);
GetSystemTime (t1);
Result := t0.wHour - t1.wHour;
end;
begin
Result := 0;
try
if FindFirst (Filename, faAnyFile, f) <> 0 then
raise Exception.Create (' File ' + Filename + ' not found');
case Filetime of
ftAccess : t := f.FindData.ftLastAccessTime;
ftCreated : t := f.FindData.ftCreationTime;
ftWrite : t := f.FindData.ftLastWriteTime;
else
raise Exception.Create (' Invalid type of file time')
end;
if not FileTimeToSystemTime (t, s) then
raise Exception.Create (' Could not convert file time to system time format');
d := GetTimeDiff;
with s do
Result := EncodeDate (wYear, wMonth, wDay) + EncodeTime (wHour + d, wMinute, wSecond, wMilliseconds);
Result := Result
finally
FindClose (f)
end
end;
A call like
ShowMessage (FormatDateTime ('dddd, d. mmmm yyyy hh:nn:ss', GetFileDateTime ('any file or folder you address here', ftCreated)))
should produce a message box showing the files / folders creation date.
Have a nice day
Volker Zeller
|
|
Zitat
|