Einzelnen Beitrag anzeigen

Vader

Registriert seit: 6. Mai 2003
804 Beiträge
 
Delphi 6 Enterprise
 
#17

Re: Erstellt (am) einer Datei ändern

  Alt 9. Okt 2004, 11:38
hallo hab den beitrag von delphi-source.de gelesen und hätte da eine frage,
wie rufe ich diese funktion auf die die dateieigenschaften ändern soll ?

In folgender Prozedur wird dargestellt, wie diese drei Daten eines Ordners oder einer Datei auch geändert werden können
Code:
function ChangeFileDate(const path: string; const 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(path), GENERIC_READ or GENERIC_WRITE, 0, nil,
  OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
  if (hFile <> INVALID_HANDLE_VALUE) then
    try
      //Umwandlung von TDateTime in Systemzeitformat
      DateTimeToSystemTime(Creation, stCreationLocal);
      DateTimeToSystemTime(LastAccess, stLastAccessLocal);
      DateTimeToSystemTime(LastWrite, stLastWriteLocal);
      //Umwandlung von Systemzeitformat in lokales Dateizeitformat
      if (SystemTimeToFileTime(stCreationLocal, ftCreationLocal)) and
      (SystemTimeToFileTime(stLastAccessLocal, ftLastAccessLocal)) and
      (SystemTimeToFileTime(stLastWriteLocal, ftLastWriteLocal)) then begin
        //Umwandlung von lokalem Dateizeitformat in Weltzeit
        if (LocalFileTimeToFileTime(ftCreationLocal, ftCreationUTC)) and
        (LocalFileTimeToFileTime(ftLastAccessLocal, ftLastAccessUTC)) and
        (LocalFileTimeToFileTime(ftLastWriteLocal, ftLastWriteUTC)) then begin
          result:=SetFileTime(hFile, @ftCreationUTC, @ftLastAccessUTC, @ftLastWriteUTC);
        end;
      end;
    finally
      CloseHandle(hFile);
    end;
end;

mfg vader
  Mit Zitat antworten Zitat