源文件一个几十G大的文件夹,对它实现文件同步到指定的路径下。
肯定不能全部复制,要求就增量和修改的部分做同步。
网上找了个例子如下
unit FileSysThread;interfaceuses
Windows, SysUtils, Classes, comctrls;type
TFileSysNotifyThread = class(TThread)
private
ErrCode: Integer;
KillAddress: PInteger;
NotifyHandle: THandle;
WatchPath: string;
WatchMask: Integer;
procedure SignalFileNotification;
protected
procedure Execute; override;
public
constructor Create(const AWatchPath: string; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
destructor Destroy; override;
end;implementationuses Dialogs;constructor TFileSysNotifyThread.Create(const AWatchPath: string; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
begin
inherited Create(True);
WatchPath := AWatchPath;
WatchMask := AWatchMask;
KillAddress := Addr(Myself);
Priority := tpLower;
FreeOnTerminate := True;
Suspended := False;
end;destructor TFileSysNotifyThread.Destroy;
begin
if NotifyHandle <> THandle(-1) then
FindCloseChangeNotification(NotifyHandle);
inherited Destroy;
KillAddress^ := 0;
end;procedure TFileSysNotifyThread.Execute;
begin
NotifyHandle := FindFirstChangeNotification(PChar(WatchPath), True, WatchMask);
if NotifyHandle <> THandle(-1) then
while not Terminated do begin
ErrCode := WaitForSingleObject(NotifyHandle, 250);
case ErrCode of
Wait_Timeout:
;
Wait_Object_0:
begin
Synchronize(SignalFileNotification);
FindNextChangeNotification(NotifyHandle);
end;
else ;
end;
end;
end;procedure TFileSysNotifyThread.SignalFileNotification;
begin
ShowMessage('文件已改变! ');
end;end.看了下是采用线程实现的,但是看不大懂constructor TFileSysNotifyThread.Create(const AWatchPath: string; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
为什么这么构造? 线程知识薄弱 求教达人讲解下~~
肯定不能全部复制,要求就增量和修改的部分做同步。
网上找了个例子如下
unit FileSysThread;interfaceuses
Windows, SysUtils, Classes, comctrls;type
TFileSysNotifyThread = class(TThread)
private
ErrCode: Integer;
KillAddress: PInteger;
NotifyHandle: THandle;
WatchPath: string;
WatchMask: Integer;
procedure SignalFileNotification;
protected
procedure Execute; override;
public
constructor Create(const AWatchPath: string; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
destructor Destroy; override;
end;implementationuses Dialogs;constructor TFileSysNotifyThread.Create(const AWatchPath: string; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
begin
inherited Create(True);
WatchPath := AWatchPath;
WatchMask := AWatchMask;
KillAddress := Addr(Myself);
Priority := tpLower;
FreeOnTerminate := True;
Suspended := False;
end;destructor TFileSysNotifyThread.Destroy;
begin
if NotifyHandle <> THandle(-1) then
FindCloseChangeNotification(NotifyHandle);
inherited Destroy;
KillAddress^ := 0;
end;procedure TFileSysNotifyThread.Execute;
begin
NotifyHandle := FindFirstChangeNotification(PChar(WatchPath), True, WatchMask);
if NotifyHandle <> THandle(-1) then
while not Terminated do begin
ErrCode := WaitForSingleObject(NotifyHandle, 250);
case ErrCode of
Wait_Timeout:
;
Wait_Object_0:
begin
Synchronize(SignalFileNotification);
FindNextChangeNotification(NotifyHandle);
end;
else ;
end;
end;
end;procedure TFileSysNotifyThread.SignalFileNotification;
begin
ShowMessage('文件已改变! ');
end;end.看了下是采用线程实现的,但是看不大懂constructor TFileSysNotifyThread.Create(const AWatchPath: string; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
为什么这么构造? 线程知识薄弱 求教达人讲解下~~
解决方案 »
- 麻烦大家帮我看一下有关SOCKET的程序,服务端和客户端一直连接不上,我都无语了
- 请教个问题!
- delphi7 listbox 修改了触发的事件是什么事件??
- 用Twriter 与TReader 对TMemoryStream操作出现错误,请帮忙
- 从来没有来过D这里,发一个帖子给自己做宣传博客,认识的兄弟给我捧场,谢谢
- 怎么由子窗口句柄得到主窗口句柄?
- 关于delphi +oracle的查询的问题! 高手请进!
- delphi 自带数据库数据之间复制问题100%结帖
- 灌水:请问,哪位知道大富翁怎么了?
- 什么是sqldriverconnect?
- Embarcadero RAD Studio XE2 编译错误问题。
- 卷土再来: Delphi中间件QuickBurro III发布在即
现在的问题是如何创建这个线程呢?AWatchPath是const,WatchPath是private.
我该如何把我想要的源文件作为参数传入。
哪位给个线程创建的实例看看!
同步时注意源删除时的处理会复杂点