Страница 1 из 1
FindFirstChangeNotification и парная к ней ф-ия
Добавлено: 24 фев 2004, 22:57
Pepper
Добрые люди подсказали что для отслеживания изменений в каталоге можно использовать ф-ию FindFirstChangeNotification и ф-ию FindNextChangeNotification... вот.
т.к. с WinApi я не очень
то прошу помочь разобраться как оно работает.
Добавлено: 26 фев 2004, 12:49
Hawk
Пример из MSDN, следит за изменениями в "C:\" и "C:\Windows" папках
Код: Выделить всё
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
// Watch the C:\WINDOWS directory for file creation and
// deletion.
dwChangeHandles[0] = FindFirstChangeNotification(
"C:\\WINDOWS", // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Watch the C:\ subtree for directory creation and
// deletion.
dwChangeHandles[1] = FindFirstChangeNotification(
"C:\\", // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes
if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Change notification is set. Now wait on both notification
// handles and refresh accordingly.
while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0:
// A file was created or deleted in C:\WINDOWS.
// Refresh this directory and restart the
// change notification. RefreshDirectory is an
// application-defined function.
RefreshDirectory("C:\\WINDOWS")
if ( FindNextChangeNotification(
dwChangeHandles[0]) == FALSE )
ExitProcess(GetLastError());
break;
case WAIT_OBJECT_0 + 1:
// A directory was created or deleted in C:\.
// Refresh the directory tree and restart the
// change notification. RefreshTree is an
// application-defined function.
RefreshTree("C:\\");
if (FindNextChangeNotification(
dwChangeHandles[1]) == FALSE)
ExitProcess(GetLastError());
break;
default:
ExitProcess(GetLastError());
}
}
Добавлено: 11 апр 2004, 11:51
Pepper
Хорошо, с этим я разобрался. Теперь возникает другой вопрос: как узнать что именно изменилось в каталоге? т.е. Какой, например, файл был удален, или наоборот создан, короче получить имя этого файла (подкаталога).