procedure TForm5.CopyNewerFiles(FromDir,ToDir:String);
var
SR1,SR2:TSearchRec;
FR1,FR2:Integer;
DT1,DT2:TDateTime;
label
FindNextOne;
begin
if (FromDir=ToDir) or (FromDir='') or (ToDir='') then exit;
if FromDir[Length(FromDir)] <> '\' then FromDir:=FromDir+'\';
if ToDir[Length(ToDir)] <> '\' then ToDir:=ToDir+'\';
FR1:=FindFirst(FromDir+'*.*',faAnyFile,SR1);
while FR1=0 do begin
if (faDirectory and Sr1.Attr <> 0) or
((Pos('.~',SR1.Name) > 0) and CheckBox1.Checked) or
(SR1.Name = '.') or (SR1.Name='..') then goto FindNextOne;
FR2:=FindFirst(ToDir+SR1.Name,faAnyFile,SR2);
Inc(UpdateCount);
if FR2 = 0 then begin
DT1:=FileDateToDateTime(SR1.Time);
DT2:=FileDateToDateTime(SR2.Time);
case CompareFileTime(TFileTime(DT1),TFileTime(DT2)) of
1:CopyFile(PChar(FromDir+SR1.Name),PChar(ToDir+SR1.Name),False);
-1:CopyFile(PChar(ToDir+SR1.Name),PChar(FromDir+SR1.Name),False);
0:Dec(UpdateCount);
end
end
else
CopyFile(PChar(FromDir+SR1.Name),PChar(ToDir+SR1.Name),False);
Dec(UpdateCount);
FindClose(SR2);
FindNextOne:
FR1:=FindNext(SR1);
end;
FindClose(SR1);
End; |