char buf[(sizeof(FILE_NOTIFY_INFORMATION)+MAX_PATH)*2];
FILE_NOTIFY_INFORMATION* pNotify=(FILE_NOTIFY_INFORMATION*)buf;
DWORD dwBytesReturned;
while(true)
{
if( ::ReadDirectoryChangesW( obj->hDir,//目录句柄
pNotify,// 一个指向FILE_NOTIFY_INFORMATION结构体的缓冲区,其中可以将获取的数据结果将其返回
sizeof(buf),
true,//是否监控子目录
FILE_NOTIFY_CHANGE_FILE_NAME|
FILE_NOTIFY_CHANGE_DIR_NAME|
FILE_NOTIFY_CHANGE_ATTRIBUTES|
FILE_NOTIFY_CHANGE_SIZE|
FILE_NOTIFY_CHANGE_LAST_WRITE|
FILE_NOTIFY_CHANGE_LAST_ACCESS|
FILE_NOTIFY_CHANGE_CREATION|
FILE_NOTIFY_CHANGE_SECURITY,
&dwBytesReturned,
NULL,
NULL ) )
{
char tmp[MAX_PATH], str1[MAX_PATH], str2[MAX_PATH];
memset( tmp, 0, sizeof(tmp) ); //ZeroMemory()
WideCharToMultiByte( CP_ACP,0,pNotify->FileName,pNotify->FileNameLength/2,tmp,99,NULL,NULL );//要转换
switch(pNotify->Action)
{
case FILE_ACTION_ADDED:
//......... 根据值判断文件操作了什么
}
}
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364391(v=vs.85).aspx