![]() |
Folder creation datetime
Delphi-Quellcode:
So, both actual and commented code returns invalid creation. What is wrong? :?
function GetFolderDate(const AFolder: string): TDateTime;
var FolderData: TWin32FileAttributeData; FileTime: _FILETIME; // FileTime: _SYSTEMTIME; DW: DWORD; begin Result := 0; FillChar(FolderData, SizeOf(FolderData), 0); if GetFileAttributesEx(PChar(AFolder), GetFileExInfoStandard, @FolderData) then begin FileTimeToLocalFileTime(FolderData.ftCreationTime, FileTime); FileTimeToDosDateTime(FileTime, LongRec(DW).Hi, LongRec(DW).Lo); Result := FileDateToDateTime(DW); // FileTimeToSystemTime(FolderData.ftCreationTime, FileTime); // Result:= SystemTimeToDateTime(FileTime); end; end; |
AW: Folder creation datetime
Did you try to parameterize the function DateTimeToStr() by including a variable of type TFormatSettings ?,
e.g.:
Delphi-Quellcode:
If that will fail, then are you absolutely shure calling for a time stamp of a truly existing foldername ? Curiously enough, if you are calling GetFolderDate() for an empty or nonexisting or misspelled foldername that will respond with a time stamp corresponding to '30.12.1899'.
procedure TForm1.Button1Click(Sender: TObject);
Var tf: TFormatSettings; begin GetLocaleFormatSettings(GetSystemDefaultLCID, tf); Showmessage(DateTimeToStr(GetFolderDate('c:\Windows'),tf)); end; |
Re: Folder creation datetime
So, problem is with conversion system time to Delphis time. :cyclops:
The same conversion method I used to get file properties and was oke, but for folders is not oke... :? |
AW: Folder creation datetime
Hi,
maybe the following code could be some help for you - feel free to use it, if you like
Delphi-Quellcode:
A call like
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;
Delphi-Quellcode:
should produce a message box showing the files / folders creation date.
ShowMessage (FormatDateTime ('dddd, d. mmmm yyyy hh:nn:ss', GetFileDateTime ('any file or folder you address here', ftCreated)))
Have a nice day |
AW: Folder creation datetime
@Volker
Deine Routine GetTimeDiff dürfte mitunter unerwartete Ergebnisse liefern ... bei uns zumindest um die Geisterstunde herum ... |
AW: Folder creation datetime
Delphi-Quellcode:
function GetFolderDate(const AFolder: string): TDateTime;
var FolderData: TWin32FileAttributeData; Systemtime,LocalTime: _SYSTEMTIME; TZ : _TIME_ZONE_INFORMATION; DW: DWORD; begin Result := 0; FillChar(FolderData, SizeOf(FolderData), 0); if GetFileAttributesEx(PChar(AFolder), GetFileExInfoStandard, @FolderData) then begin FileTimeToSystemTime(FolderData.ftCreationTime, Systemtime); GetTimeZoneInformation (TZ); SystemTimeToTzSpecificLocalTime(@TZ,Systemtime,LocalTime); Result:= SystemTimeToDateTime(LocalTime); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:27 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz