AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Folder creation datetime

Ein Thema von WojTec · begonnen am 26. Mär 2013 · letzter Beitrag vom 27. Mär 2013
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Folder creation datetime

  Alt 26. Mär 2013, 18:51
Delphi-Quellcode:
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;
So, both actual and commented code returns invalid creation. What is wrong?
  Mit Zitat antworten Zitat
ASM

Registriert seit: 15. Aug 2004
165 Beiträge
 
Delphi 7 Enterprise
 
#2

AW: Folder creation datetime

  Alt 26. Mär 2013, 20:13
Did you try to parameterize the function DateTimeToStr() by including a variable of type TFormatSettings ?,
e.g.:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
Var tf: TFormatSettings;
begin
 GetLocaleFormatSettings(GetSystemDefaultLCID, tf);
 Showmessage(DateTimeToStr(GetFolderDate('c:\Windows'),tf));
end;
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'.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Folder creation datetime

  Alt 26. Mär 2013, 20:26
So, problem is with conversion system time to Delphis time.

The same conversion method I used to get file properties and was oke, but for folders is not oke...
  Mit Zitat antworten Zitat
Volker Z.

Registriert seit: 3. Dez 2012
Ort: Augsburg, Bayern, Süddeutschland
419 Beiträge
 
Delphi XE4 Ultimate
 
#4

AW: Folder creation datetime

  Alt 27. Mär 2013, 02: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
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#5

AW: Folder creation datetime

  Alt 27. Mär 2013, 06:33
@Volker

Deine Routine GetTimeDiff dürfte mitunter unerwartete Ergebnisse liefern ... bei uns zumindest um die Geisterstunde herum ...
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#6

AW: Folder creation datetime

  Alt 27. Mär 2013, 18:24
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;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:27 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz