// Watch the C:\WINDOWS directory for file creation and // deletion.
dwChangeHandles = FindFirstChangeNotification( "C:\\The_Dirctory_Your_File_In", // directory to watch FALSE, // do not watch the subtree FILE_NOTIFY_CHANGE_LAST_WRITE); // watch file name changes
if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError());
// Change notification is set. Now wait on both notification // handles and refresh accordingly.
while (TRUE) {
// Wait for notification. dwWaitStatus = WaitForSingleObject(dwChangeHandles,INFINITE);
打开与读不知道。
HANDLE dwChangeHandles;
// Watch the C:\WINDOWS directory for file creation and
// deletion.
dwChangeHandles = FindFirstChangeNotification(
"C:\\The_Dirctory_Your_File_In", // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_LAST_WRITE); // watch file name changes
if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Change notification is set. Now wait on both notification
// handles and refresh accordingly.
while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForSingleObject(dwChangeHandles,INFINITE);
if ( FindNextChangeNotification(dwChangeHandles) == FALSE )
ExitProcess(GetLastError());
else
{
//判断是否你所要监视的文件,是否被改动过。
//如果被改动过,则记录下这次改动。例如:计数器加一(i++)
}}