Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Verzeichnis / Ordner Erstellungsdatum (https://www.delphipraxis.net/139086-verzeichnis-ordner-erstellungsdatum.html)

doctor-x 23. Aug 2009 10:27


Verzeichnis / Ordner Erstellungsdatum
 
Hallo Leute,

ich hab hier schon einiges zum thema Erstllungsdatum von Dateien ändern gefunden, jadoch nichts dazu wie das bei Ordnern funktioniret.

Ich möchte einen ordner kopieren und es sollen alle Ordner und Unterordner das alte Erstellungsdatum behalten.
Habe mich schon damit abgefunden das das nicht so leicht ist, und ich die kopierten Ordner nachträglich bearbeiten muss, aber wie?

Danke schon mal im Voraus!

himitsu 23. Aug 2009 10:47

Re: Verzeichnis / Ordner Erstellungsdatum
 
na ganz genauso, nur daß man dort ganz einfach das Handle eines Ordners verwendet, anstatt das einer Datei :zwinker:

doctor-x 23. Aug 2009 16:59

Re: Verzeichnis / Ordner Erstellungsdatum
 
Habe ein wenig rumprobiert, das ist dabei raus gekommen:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  aHandle: THandle;
  FindData, FindData2: TWIN32FindData;
begin
  FindFirstFile('c:\abc', FindData); // Zeitstempel lesen
  DoFileWork(FO_COPY, 'c:\abc', 'd:\abc', FOF_SILENT or FOF_NOERRORUI); //Kopieren
  aHandle := FindFirstFile('d:\abc', FindData2); //Handle holen
  SetFileTime(aHandle, @FindData.ftCreationTime, @FindData.ftLastAccessTime, @FindData.ftLastWriteTime); //Zeitstempel schreiben
end;
aber SetFileTime schlägt immer fehl :gruebel:

himitsu 23. Aug 2009 17:21

Re: Verzeichnis / Ordner Erstellungsdatum
 
FindFirstFile liefert das Handle des Suchergebnisses

CreateFile wäre hier passender (laß dich vom File im Namen nicht irreleiten, ein Verzeichnis ist ja im Prinzip auch nur 'ne Datei)

doctor-x 23. Aug 2009 18:26

Re: Verzeichnis / Ordner Erstellungsdatum
 
Das habe ich auch schon versucht:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  aHandle: THandle;
  LastAccessTime, CreationTime, LastWriteTime: TFileTime;
begin
  aHandle := CreateFile('c:\abc', FILE_READ_ATTRIBUTES, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  Edit1.Text := BoolToStr(GetFileTime(aHandle, @CreationTime, @LastAccessTime, @LastWriteTime));
  DoFileWork(FO_COPY, 'c:\abc', 'd:\abc', FOF_SILENT or FOF_NOERRORUI);
  aHandle := CreateFile('d:\abc', FILE_WRITE_ATTRIBUTES, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  Edit2.Text := BoolToStr(SetFileTime(aHandle, @CreationTime, @LastAccessTime, @LastWriteTime));
end;
Es liefert aber sowohl GetFileTime als auch SetFileTime False zurück.
Hab auch schon versucht den Dateinamen mit \ zu beenden ('c:\abc\') geht aber auch nicht.
(Is bestimmt irgend etwas total banales, aber ich komm einfach nicht drauf...)

DeddyH 23. Aug 2009 18:31

Re: Verzeichnis / Ordner Erstellungsdatum
 
Zitat:

Zitat von MSDN
A handle to the file or directory. The handle must have been created using the CreateFile function with the FILE_WRITE_ATTRIBUTES access right.


doctor-x 23. Aug 2009 18:46

Re: Verzeichnis / Ordner Erstellungsdatum
 
Hab es auch mit

Delphi-Quellcode:
aHandle := CreateFile('c:\abc', FILE_WRITE_ATTRIBUTES, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_DIRECTORY, 0);
und

Delphi-Quellcode:
aHandle := CreateFile('c:\abc', FILE_WRITE_ATTRIBUTES, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
versucht, gibt aber das selbe ergebniss :(

himitsu 23. Aug 2009 18:47

Re: Verzeichnis / Ordner Erstellungsdatum
 
ich glaub da sind dieses Zitate wichtiger
Zitat:

To obtain a handle to an existing directory, call the CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag.
bzw.
Zitat:

FILE_FLAG_BACKUP_SEMANTICS

The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges in a Token.

You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead of a file handle. For more information, see the Remarks section.
Delphi-Quellcode:
aHandle := CreateFile('c:\abc', FILE_READ_ATTRIBUTES,
  FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
  FILE_FLAG_BACKUP_SEMANTICS, 0);
if aHandle <> INVALID_HANDLE_VALUE then begin

end else ShowMessage(SysErrorMessage(GetLastError));

DeddyH 23. Aug 2009 18:51

Re: Verzeichnis / Ordner Erstellungsdatum
 
Immer alles vorsagen, dabei kann doch jeder selbst nachlesen :tongue:

doctor-x 23. Aug 2009 18:56

Re: Verzeichnis / Ordner Erstellungsdatum
 
Danke!
Das funktioniert einwandfrei :)

Hier noch der Code für alle die noch auf dieses problem stoßen...

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  aHandle: THandle;
  LastAccessTime, CreationTime, LastWriteTime: TFileTime;
begin
  aHandle := CreateFile('c:\abc', FILE_READ_ATTRIBUTES,
                        FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
                        FILE_FLAG_BACKUP_SEMANTICS, 0);
  GetFileTime(aHandle, @CreationTime, @LastAccessTime, @LastWriteTime);
  DoFileWork(FO_COPY, 'c:\abc', 'd:\abc', FOF_SILENT or FOF_NOERRORUI);
  aHandle := CreateFile('d:\abc', FILE_WRITE_ATTRIBUTES,
                        FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
                        FILE_FLAG_BACKUP_SEMANTICS, 0);
  SetFileTime(aHandle, @CreationTime, @LastAccessTime, @LastWriteTime);
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:47 Uhr.
Seite 1 von 2  1 2      

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