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.