Need a notification on deletion of a file/directory

Need a notification on deletion of a file/directory

Post by uday.se » Sat, 21 Jan 2006 00:12:20


Hi,

I am using CreateIoCompletionPort(), ReadDirectoryChangesW() and
GetQueuedCompletionStatus() APIs to get notification of file/folder
deletion. However, I need to determine whether the entity deleted is a
file or folder and accordingly perform an appropriate action.
I have noticed that ReadDirectoryChangesW() has a filter criteria
FILE_NOTIFY_CHANGE_DIR_NAME to get notification of folder
creation/deletion/rename. However AFAIK, this filter will not notify my
application about deletion of file. I am currently using
"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_CREATION |
FILE_NOTIFY_CHANGE_SECURITY" filter criteria.

Any help is highly regarded.

Thanks in advance,
- Uday
 
 
 

Need a notification on deletion of a file/directory

Post by Kellie Fit » Sat, 21 Jan 2006 00:59:40

Hi,

Well, when your application is monitoring a folder for file
deletion by using the API ReadDirectoryChangesW(), you will
receive a notification that the file have been moved from the
target folder in the FILE_NOTIFY_INFORMATION structure, then
you have to determine if the file was really deleted from the
hardDrive, or the endUser just moved it to another location.

http://www.yqcomputer.com/

Kellie.

 
 
 

Need a notification on deletion of a file/directory

Post by uday.se » Sat, 21 Jan 2006 14:25:45

Hi Kellie,

Thanks for the pointer to MSDN. However, my concern is when
"FILE_ACTION_REMOVED" notification arrives, is there any way to detect
whether the deleted element is a file or a folder? Once a file or
folder is deleted there is no way to get its attribute.

- Uday
 
 
 

Need a notification on deletion of a file/directory

Post by Kellie Fit » Sat, 21 Jan 2006 17:35:42

Hi,

You should use the API ReadDirectoryChangesW() when you need to
monitor a single or multiple folders for FILES being deleted and
changed, potentially on different drives or just the local drive.

One viable strategy is to issue a ReadDirectoryChangesW() for every
folder, however, sufficient test coverage is really important here,
and when a FILE gets moved or modified, your application will get
the name of that file in the FILE_NOTIFY_INFORMATION structure,
the file name will be in the Unicode Character Format.

Kellie.