AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Cross-Platform-Entwicklung Exaktes Filecopy für Windows und Android
Thema durchsuchen
Ansicht
Themen-Optionen

Exaktes Filecopy für Windows und Android

Ein Thema von skoschke · begonnen am 30. Nov 2018 · letzter Beitrag vom 2. Dez 2018
 
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Exaktes Filecopy

  Alt 30. Nov 2018, 10:07
Falls es Probleme gibt, das sollte es bewirken.
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetCreationDate(fn:string):TDateTime;
var
  FHandle : THandle;
  A,C,W : TFileTime;
  SysTimeStruct: SYSTEMTIME;
begin
    Fhandle:=createfile(PChar(Fn), 0,FILE_SHARE_READ, nil, OPEN_EXISTING, SECURITY_ANONYMOUS, 0);
    if GetTimeZoneInformation(TimeZoneInfo) <> $FFFFFFFF then
      if GetFileTime(FHandle,@C, @A, @W) then
      begin
        FileTimeToSystemTime(C, SysTimeStruct);
        Result := SystemTimeToDateTime(SysTimeStruct);
      end;
    FileClose(FHandle);
end;

function SetCreationDate(FileName: string; dtCreation: TDateTime): Boolean;
var
  hHandle: THandle;
  ftCreation: TFiletime;

  function DTtoFT(dt: TDateTime): TFiletime;
  var
    dwft: DWORD;
    ft: TFiletime;
  begin
    dwft := DateTimeToFileDate(dt);
    DosDateTimeToFileTime(LongRec(dwft).Hi, LongRec(dwft).Lo, ft);
    LocalFileTimeToFileTime(ft, Result);
  end;

begin
  hhandle := CreateFile(PChar(FileName),
  GENERIC_READ or GENERIC_WRITE,0,nil,
  OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS, 0);

  if hHandle <> INVALID_HANDLE_VALUE then
  begin
    try
      ftCreation := DTtoFT(dtCreation);
      Result := SetFileTime(hHandle, @ftCreation, nil, nil);
    finally
      CloseHandle(hHandle);
    end;
  end
  else
    Result := False;
end;


procedure TForm1.Button1Click(Sender: TObject);
var getdate: tdatetime;
sor,des: string;
begin
sor :='c:\bdlog.txt';
des := 'd:\bdlog.txt';
getdate := GetCreationDate(sor);
CopyFile(PChar(sor),PChar(des),false);
SetCreationDate(des, getdate);
ShowMessage(DateTimeToStr(getdate));
end;

end.
Gruß vom KodeZwerg

Geändert von KodeZwerg (30. Nov 2018 um 11:34 Uhr)
  Mit Zitat antworten Zitat
 


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 18:37 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-2025 by Thomas Breitkreuz