C 監測資料夾變化

2021-06-09 15:19:23 字數 1898 閱讀 1137

#ifndef __filesystemwatcher_hpp__

#define __filesystemwatcher_hpp__

#if(_win32_winnt < 0x0400)

#define _win32_winnt 0x0400

#endif

#include

class filesystemwatcher

;enum action

;typedef void (__stdcall *lpdealfunction)( action act, lpcwstr filename, lpvoid lparam );

filesystemwatcher();

~filesystemwatcher();

// lpctstr dir: ended-with "\\"

bool run( lpctstr dir, bool bwatchsubtree, dword dwnotifyfilter, lpdealfunction dealfun, lpvoid lparam );

void close( dword dwmilliseconds=infinite );

private: // no-impl

filesystemwatcher( const filesystemwatcher& );

filesystemwatcher operator=( const filesystemwatcher );

private:

handle m_hdir;

dword m_dwnotifyfilter;

bool m_bwatchsubtree;

handle m_hthread;

volatile bool m_brequeststop;

lpdealfunction m_dealfun;

lpvoid m_dealfunparam;

static dword winapi routine( lpvoid lparam );

};#endif // __filesystemwatcher_hpp__

#include "filesystemwatcher.h"

#include

filesystemwatcher::filesystemwatcher() : m_hdir(invalid_handle_value), m_hthread(null)

filesystemwatcher::~filesystemwatcher()

bool filesystemwatcher::run( lpctstr dir, bool bwatchsubtree, dword dwnotifyfilter, lpdealfunction dealfun, lpvoid lparam )

return null!=m_hthread;

}void filesystemwatcher::close( dword dwmilliseconds )

if( invalid_handle_value != m_hdir )

}dword winapi filesystemwatcher::routine( lpvoid lparam )

}else

}return 0;

}#include "stdafx.h"

#include "filesystemwatcher.h"

#include

#include

#include

#include

#include

void __stdcall mydeal( filesystemwatcher::action act, lpcwstr filename, lpvoid lparam )

pre = act;

}int main()

C 監測資料夾內檔案操作

直接用控制項,如下 publicstaticfilesystemwatcher watcher newfilesystemwatcher 接下來就是為對watcher 的事件捕獲並進行相應處理,如下 watcher.changed newfilesystemeventhandler onchange...

C 中監控資料夾的變化

filesystemwatcher 用法 在應用filesystemwatcher物件之前,你必須了解這個物件的一些基本屬性和事件。毫無疑問,這個物件的最重要的屬性為 enableraisingevents 屬性。這個屬性決定物件在收到改變通知時是否提交事件。如果enableraisingevent...

如何監視資料夾變化

使用工具箱中 元件中的filesystemwatcher 控制項 看下 對它的說明 public class filesystemwatcher system.componentmodel.component system.io 的成員 摘要 偵聽檔案系統更改通知,並在目錄或目錄中的檔案發生更改時引...