AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Datei öffnen, speichern[Prob gelöst]
Thema durchsuchen
Ansicht
Themen-Optionen

Datei öffnen, speichern[Prob gelöst]

Ein Thema von synex · begonnen am 27. Okt 2003 · letzter Beitrag vom 28. Okt 2003
Antwort Antwort
synex

Registriert seit: 14. Apr 2003
147 Beiträge
 
Delphi 6 Personal
 
#1

Re: Datei öffnen, speichern[Prob gelöst]

  Alt 28. Okt 2003, 20:13
Diese beiden Prozeduren hab ich mir hier her geklaut
Delphi-Quellcode:
//Dateierstellung etc ändern
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;

//datei datum sachen auslesen
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;
Und so hab ich das in meinem Programm umgesetzt: (in der Listbox stehen die dateinamen mit Pfad in der endgültigen Reihenfolge)

Delphi-Quellcode:
procedure TForm1.Button15Click(Sender: TObject);
var i:integer;
  datum,erstellt,geaendert,access:tdatetime;
begin
datum:=now-(listbox1.Count-i); //der Einfachheit halber ist der Datumsunterschied genau 1 Tag
for i:= 0 to listbox1.Count-1 do
  begin
  getfiledate(listbox3.Items.Strings[i],erstellt,access,geaendert); //Daten auslesen
  changefiledate(listbox3.Items.Strings[i],datum,datum,datum); //und neue Daten setzen, Erstellungsdatum, LastAccess und LastWrite wird gleichgesetzt
  end;
end;
Und das wars auch schon.

MfG synex
  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 04:44 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 by Thomas Breitkreuz