Einzelnen Beitrag anzeigen

ReDoX
(Gast)

n/a Beiträge
 
#2

Re: Details abfragen mit Indy

  Alt 22. Sep 2004, 10:37
Hier ist aber nicht von mir:

Delphi-Quellcode:
function GetFileDate(const FileName: string; out Creation, LastAccess,
  LastWrite: TDateTime): Boolean;
var
  hFile: THandle;
  ftCreationUTC, ftLastAccessUTC, ftLastWriteUTC: TFileTime;
  ftCreationLocal, ftLastAccessLocal, ftLastWriteLocal: TFileTime;
  stCreationLocal, stLastAccessLocal, stLastWriteLocal: TSystemTime;
begin
  result:=false;
  hFile := CreateFile(PChar(FileName), GENERIC_READ, 0, nil,
  OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
  if (hFile <> INVALID_HANDLE_VALUE) then begin
    try
      //Ermittlung des Dateidatums in UTC (Weltzeit)
      if GetFileTime(hFile, @ftCreationUTC, @ftLastAccessUTC, @ftLastWriteUTC) then begin
        //Umrechnung in Ortszeit
        if FileTimeToLocalFileTime(ftCreationUTC, ftCreationLocal)
        and FileTimeToLocalFileTime(ftLastAccessUTC, ftLastAccessLocal)
        and FileTimeToLocalFileTime(ftLastWriteUTC, ftLastWriteLocal) then begin
          //Umwandlung in Systemdatumformat
          if FileTimeToSystemTime(ftCreationLocal, stCreationLocal)
          and FileTimeToSystemTime(ftLastAccessLocal, stLastAccessLocal)
          and FileTimeToSystemTime(ftLastWriteLocal, stLastWriteLocal) then begin
            //Zuweisung der Rückgabewerte
            Creation := SystemTimeToDateTime(stCreationLocal);
            LastAccess := SystemTimeToDateTime(stLastAccessLocal);
            LastWrite := SystemTimeToDateTime(stLastWriteLocal);
            result:=true;
          end;
        end;
      end;
    finally
      CloseHandle(hFile);
    end;
  end;
end;







procedure TForm1.Button1Click(Sender: TObject);
var erstellung, zugriff, schreibzugriff: TDateTime;
begin
  GetFileDate('c:\temp\test.bmp', erzeugung, zugriff, schreibzugriff);
  ShowMessage('Erstellung: '+DateTimeToStr(erstellung)+#13#10+'Letzter Zugriff: '+
  DateTimeToStr(zugriff)+#13#10+'Letzter Schreibzugriff: '+DateTimeToStr(schreibzugriff));
end;
Mfg MrScholz
  Mit Zitat antworten Zitat