源文件一个几十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);
为什么这么构造?    线程知识薄弱  求教达人讲解下~~

解决方案 »

  1.   

    构造函数的参数这样理解:AWatchPath,需要监控并同步的目录路径AWatchMask,同步模式参数,这个参考FindFirstChangeNotification函数的第三个参数,请查MSDN:http://msdn.microsoft.com/en-us/library/windows/desktop/aa364417(v=vs.85).aspxMyself,文件变化时的回调处理
      

  2.   

    感谢楼上的指点,对FindFirstChangeNotification了解的更多了。
    现在的问题是如何创建这个线程呢?AWatchPath是const,WatchPath是private.
    我该如何把我想要的源文件作为参数传入。
    哪位给个线程创建的实例看看!
      

  3.   

    无非是写个循环,去判断文件是否有更新<以更新时间或文件大小判断>作处理。
    同步时注意源删除时的处理会复杂点