0

I'm trying to monitor a directory using ReadDirectoryChangesW. Whenever a new file is added to the directory I monitor the application should print it's name. The application works fine if I copy one file at a time, but if I try,lets say 2 files at a time, it recognize only one of them.

I'm using this function synchronously.

Here is the code:

The handle to the directory:

HANDLE hDir = CreateFile( 
    "d:\\Detect", /* pointer to the file name */
    FILE_LIST_DIRECTORY,                /* access (read-write) mode */
    FILE_SHARE_READ|FILE_SHARE_DELETE,  /* share mode */
    NULL, /* security descriptor */
    OPEN_EXISTING, /* how to create */
    FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */
    NULL /* file with attributes to copy */
);

And ReadDirectoryChangesW:

ReadDirectoryChangesW(hDir,&Buffer,sizeof(Buffer),FALSE,
    FILE_NOTIFY_CHANGE_SECURITY|
    FILE_NOTIFY_CHANGE_CREATION|
    FILE_NOTIFY_CHANGE_LAST_ACCESS|
    FILE_NOTIFY_CHANGE_LAST_WRITE|
    FILE_NOTIFY_CHANGE_SIZE|
    FILE_NOTIFY_CHANGE_ATTRIBUTES|
    FILE_NOTIFY_CHANGE_DIR_NAME|
    FILE_NOTIFY_CHANGE_FILE_NAME,&bytesReturned,NULL,NULL);
4

0 回答 0