Registriert seit: 1. Feb 2018
3.691 Beiträge
Delphi 11 Alexandria
|
AW: FindFirst TSearchRec setzen
12. Mai 2018, 19:55
Ich weiß nicht ob CopyFileEx die Attribute (creation time etc) mitkopiert, auf jeden fall hier ein wenig Delphi um ans Ziel zu gelangen:
Delphi-Quellcode:
function GetCreationDate(fn:string):TDateTime;
var
FHandle : THandle;
AT,CT,WT : TSystemTime;
A,C,W : TFileTime;
begin
Fhandle:=createfile(Pchar(fn), 0,FILE_SHARE_READ, nil, OPEN_EXISTING, SECURITY_ANONYMOUS, 0);
if GetFileTime(FHandle,@C,@A,@W) then
begin
FileTimeToSystemTime(C,CT);
result := SystemTimeToDateTime(CT);
end;
FileClose(FHandle);
end;
procedure SetCreationDate(fn: string; NewDateTime: TDateTime);
var
FileHandle: Integer;
FileTime: TFileTime;
LFT: TFileTime;
LST: TSystemTime;
begin
DecodeDate(NewDateTime, LST.wYear, LST.wMonth, LST.wDay);
DecodeTime(NewDateTime, LST.wHour, LST.wMinute, LST.wSecond, LST.wMilliSeconds);
if SystemTimeToFileTime(LST, LFT) then
begin
if LocalFileTimeToFileTime(LFT, FileTime) then
begin
FileHandle := FileOpen(fn, fmOpenReadWrite or fmShareExclusive);
SetFileTime(FileHandle, @FileTime, @FileTime, nil);
end;
end;
FileClose(FileHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
var getdate: tdatetime;
begin
getdate := GetCreationDate('c:\autoexec.bat');
copyfile('c:\autoexec.bat','d:\autoexec.dat',false);
SetCreationDate('d:\autoexec.dat', getdate);
end;
oder
Delphi-Quellcode:
procedure TMainForm.CopyLtoR(Sender: TObject);
var
I: Integer;
FileName: String;
SourceFilePath: String;
DestFilePath: String;
GetDate: tDateTime;
begin
I := 0;
While I <= JamShellList1.SelectedFiles.Count - 1 do
Begin
SourceFilePath := JamShellList1.Path + JamShellList1.SelectedFiles[I];
DestFilePath := JamShellList2.Path + JamShellList1.SelectedFiles[I];
GetDate := GetCreationDate(SourceFilePath);
// add something to check that the file soesn't already exist...if file
//doesn't exist then
CopyFile(PWideChar(SourceFilePath), PWideChar(DestFilePath),False);
SetCreationDate(SourceFilePath, GetDate);
I := I + 1;
End;;
end;
Gefunden hier.
Viel Glück!
|
|
Zitat
|