Article ID: 193773
Article Last Modified on 7/1/2004
DECLARE LONG WaitForSingleObject IN kernel32 ;
INTEGER hHandle, ;
INTEGER dwMilliseconds
DECLARE LONG FindFirstChangeNotification IN kernel32 ;
STRING lpPathName, ;
INTEGER bWatchSubtree, ;
INTEGER dwNotifyFilter AS LONG)
DECLARE LONG FindNextChangeNotification IN kernel32 ;
INTEGER hChangeHandle
DECLARE LONG GetLastError IN kernel32
DECLARE LONG FindCloseChangeNotification IN kernel32 ;
INTEGER hChangeHandle
* Only the second constant is demonstrated in this
* example; the others are listed for convenience.
* A file has been created, renamed or deleted.
#DEFINE FILE_NOTIFY_CHANGE_FILE_NAME 0x01
* Directory has been created, renamed or deleted.
#DEFINE FILE_NOTIFY_CHANGE_DIR_NAME 0x02
* A file's attribute (archive, read-only) has been changed.
#DEFINE FILE_NOTIFY_CHANGE_ATTRIBUTES 0x04
* A file's size has changed.
#DEFINE FILE_NOTIFY_CHANGE_SIZE 0x08
* A file's last write data has changed.
#DEFINE FILE_NOTIFY_CHANGE_LAST_WRITE 0x10
* A security descriptor for a directory or file has been changed.
#DEFINE FILE_NOTIFY_CHANGE_SECURITY 0x100
* Look for any changes - bitwise OR these values together.
#DEFINE FILE_NOTIFY_ALL = FILE_NOTIFY_CHANGE_ATTRIBUTES BITOR ;
FILE_NOTIFY_CHANGE_DIR_NAME BITOR ;
FILE_NOTIFY_CHANGE_FILE_NAME BITOR ;
FILE_NOTIFY_CHANGE_LAST_WRITE BITOR ;
FILE_NOTIFY_CHANGE_SECURITY BITOR ;
FILE_NOTIFY_CHANGE_SIZE
#DEFINE INVALID_HANDLE_VALUE -1
#DEFINE INFINITE 2147483647
#DEFINE WAIT_FAILED 2147483647
#DEFINE True -1
#DEFINE False 0
lcPathSpec = "C:\TEST"
lbWatchSubtree = True
* Watch for a directory added, changed or deleted beneath the
* specified PathSpec.
lihNotify = FindFirstChangeNotification(lcPathSpec, lbWatchSubtree, ;
FILE_NOTIFY_CHANGE_DIR_NAME)
IF lihNotify <= INVALID_HANDLE_VALUE
MESSAGEBOX ("FindFirstChangeNotification failed. Error code: " + ;
LTRIM(STR(GetLastError())))
RETURN
ELSE
* Uncomment for debugging purposes.
* MessageBox ("FindFirstChangfeNotification instantiation ;
* succeeded. Handle is: " + ltrim(str(lihNotify)))
ENDIF
* Now, go into a wait state.
* This is going to look like a hang, since the IDE is all in
* one thread.
liWaitReturn = WaitForSingleObject(lihNotify, INFINITE)
IF liWaitReturn >= WAIT_FAILED
MESSAGEBOX ("WaitForSingleObject failed. Error is: " + ;
LTRIM(STR(GetLastError())))
RETURN
ELSE
MESSAGEBOX ("Directory change in " + lcPathSpec + " occurred")
ENDIF
liWaitReturn = FindCloseChangeNotification(lihNotify)
Additional query words: kbVFp600 kbAPI temp temporary bit attribute
Keywords: kbhowto kbcode KB193773