急問..........同步問題..........各位大俠幫幫忙..... ( 积分: 50 )

S

skc

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Synch;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl, StdCtrls, ExtCtrls, AdvSplitter, Registry, ComCtrls, FolderTree;
type
TForm1 = class(TForm)
AdvSplitter1: TAdvSplitter;
Panel1: TPanel;
DC1: TDriveComboBox;
DC2: TDriveComboBox;
DL1: TDirectoryListBox;
DL2: TDirectoryListBox;
FL1: TFileListBox;
FL2: TFileListBox;
Button1: TButton;
Panel2: TPanel;
Panel3: TPanel;
IgnoreBox: TCheckBox;
MustExistBox: TCheckBox;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure CopyNewerFiles(FromDir,ToDir:String);
private
{ Private declarations }
UpdateCount:Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormShow(Sender: TObject);
var
r:TRegIniFIle;
NewDir:String;
begin
DC1.Align:=alTop;
DC2.Align:=alTop;
DL1.Align:=alTop;
DL2.Align:=alTop;
FL1.Align:=alClient;
FL2.Align:=alClient;
AdvSplitter1.Center;
R:=TRegIniFile.Create('File Synchronizer');
NewDir:=r.ReadString('Directory','1','');
if (NewDir <> '') and DirectoryExists(NewDir) then
DL1.Directory:=NewDir;
NewDir:=r.ReadString('Directory','2','');
if (NewDir <> '') and DirectoryExists(NewDir) then
DL2.Directory:=NewDir;
IgnoreBox.Checked:=r.ReadBool('General','Ignore ~ files',true);
MustExistBox.Checked:=r.ReadBool('General','Must Exist',False);
R.Free;
end;

procedure TForm1.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=0do
begin
if (faDirectory and Sr1.Attr <> 0) or
((Pos('.~',SR1.Name) > 0) and IgnoreBox.Checked) or
(SR1.Name = '.') or (SR1.Name='..') then
goto FindNextOne;
Caption:='Checking: '+SR1.Name;
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
if not MustExistBox.checked then
CopyFile(PChar(FromDir+SR1.Name),PChar(ToDir+SR1.Name),False)
else
Dec(UpdateCount);
FindClose(SR2);
FindNextOne:
FR1:=FindNext(SR1);
end;
FindClose(SR1);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
R:TRegIniFile;
begin
UpdateCount:=0;
CopyNewerFiles(DL1.Directory,DL2.Directory);
CopyNewerFiles(DL2.Directory,DL1.Directory);
FL1.Refresh;
FL2.Refresh;
R:=TRegIniFile.Create('File Synchronizer');
r.WriteString('Directory','1',DL1.Directory);
r.WriteString('Directory','2',DL2.Directory);
r.WriteBool('General','Ignore ~ files',IgnoreBox.Checked);
r.WriteBool('General','Must Exist',MustExistBox.Checked);
R.Free;
Caption:='File Synchronizer';
MessageBox(GetActiveWindow,PChar('Updated '+IntToStr(UpdateCount)+' File(s)...'),
'Synchronization Complete!',MB_ICONINFORMATION);
end;

end.

以上是的源碼是雙向的同步,怎樣才可以修改成單向呢....
還有就是怎樣才能修改成包含文件夾內的子文件夾一起進行呢.....
請各位大大幫幫忙......
 
unit Synch;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl, StdCtrls, ExtCtrls, AdvSplitter, Registry, ComCtrls, FolderTree;
type
TForm1 = class(TForm)
AdvSplitter1: TAdvSplitter;
Panel1: TPanel;
DC1: TDriveComboBox;
DC2: TDriveComboBox;
DL1: TDirectoryListBox;
DL2: TDirectoryListBox;
FL1: TFileListBox;
FL2: TFileListBox;
Button1: TButton;
Panel2: TPanel;
Panel3: TPanel;
IgnoreBox: TCheckBox;
MustExistBox: TCheckBox;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure CopyNewerFiles(FromDir,ToDir:String);
private
{ Private declarations }
UpdateCount:Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormShow(Sender: TObject);
var
r:TRegIniFIle;
NewDir:String;
begin
DC1.Align:=alTop;
DC2.Align:=alTop;
DL1.Align:=alTop;
DL2.Align:=alTop;
FL1.Align:=alClient;
FL2.Align:=alClient;
AdvSplitter1.Center;
R:=TRegIniFile.Create('File Synchronizer');
NewDir:=r.ReadString('Directory','1','');
if (NewDir <> '') and DirectoryExists(NewDir) then
DL1.Directory:=NewDir;
NewDir:=r.ReadString('Directory','2','');
if (NewDir <> '') and DirectoryExists(NewDir) then
DL2.Directory:=NewDir;
IgnoreBox.Checked:=r.ReadBool('General','Ignore ~ files',true);
MustExistBox.Checked:=r.ReadBool('General','Must Exist',False);
R.Free;
end;

procedure TForm1.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=0do
begin
if (faDirectory and Sr1.Attr <> 0) or
((Pos('.~',SR1.Name) > 0) and IgnoreBox.Checked) or
(SR1.Name = '.') or (SR1.Name='..') then
goto FindNextOne;
Caption:='Checking: '+SR1.Name;
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
if not MustExistBox.checked then
CopyFile(PChar(FromDir+SR1.Name),PChar(ToDir+SR1.Name),False)
else
Dec(UpdateCount);
FindClose(SR2);
FindNextOne:
FR1:=FindNext(SR1);
end;
FindClose(SR1);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
R:TRegIniFile;
begin
UpdateCount:=0;
CopyNewerFiles(DL1.Directory,DL2.Directory);
CopyNewerFiles(DL2.Directory,DL1.Directory);
FL1.Refresh;
FL2.Refresh;
R:=TRegIniFile.Create('File Synchronizer');
r.WriteString('Directory','1',DL1.Directory);
r.WriteString('Directory','2',DL2.Directory);
r.WriteBool('General','Ignore ~ files',IgnoreBox.Checked);
r.WriteBool('General','Must Exist',MustExistBox.Checked);
R.Free;
Caption:='File Synchronizer';
MessageBox(GetActiveWindow,PChar('Updated '+IntToStr(UpdateCount)+' File(s)...'),
'Synchronization Complete!',MB_ICONINFORMATION);
end;

end.

以上是的源碼是雙向的同步,怎樣才可以修改成單向呢....
還有就是怎樣才能修改成包含文件夾內的子文件夾一起進行呢.....
請各位大大幫幫忙......
 
急需.....請各位大俠幫幫忙呢....現在沒有分..等我有分再報答你們 好嗎?
 
顶部