我想用函数FindFirstChangeNotification实现 当文件夹里面有新的文件产生时就提示我去操作该文件, 我看了有C语言的例子不过没看过有delphi的例子 哪位大哥有delphi写的例子 提供一下           小弟谢谢了

解决方案 »

  1.   

    先用FindFirstChangeNotification登记要监测的文件夹
    然后用WaitForSingleObject函数来等待文件变化事件的到来,并处理该时间
    在处理后如果需要继续监测,那么还要 调用FindNextChangeNotification(…)
    结束监视时要用FindCloseChangeNotification 
    这个要放到线程里面HANDLE FindFirstChangeNotification(
        LPCTSTR lpPathName, // pointer to name of directory to watch  
        BOOL bWatchSubtree, // flag for monitoring directory or directory tree  
        DWORD dwNotifyFilter  // filter conditions to watch for 
       );
    第1个参数指定路径
    第2个为true就表示含子目录,false为当前目录
    第3个是参数,有很多,你看下WIN32SDK
    返回值通过调用WaitForSingleObject进行等待
      

  2.   

    随便写的,如果监视的目录没有变化,这个线程就一直假死,慎重操作uses QDialog;var
    S:WideString;
    H:THandle;
    begin
    if not SelectDirectory('','',S) then exit;H:=FindFirstChangeNotification(Pchar(String(S)),true,FILE_NOTIFY_CHANGE_FILE_NAME or FILE_NOTIFY_CHANGE_DIR_NAME); //监视改文件名或目录名
    if WaitForSingleObject(H,INFINITE)=WAIT_OBJECT_0 then begin //监视等待
     showmessage('有变化');
    end;
    FindCloseChangeNotification(H); //结束监视
    end;
      

  3.   

    看我的blog里..有一个线程的组件可以用....