What's the best method to have a program periodically check the contents of a directory ( to see if files in the directory have been added or deleted ). Is there a way to have a message sent to a program if the contents of a directory change? Thanks for any information.
use GetFileAttributesEx (also used on folders) to fill a WIN32_FILE_ATTRIBUTE_DATA structure
it has creation time, last access time, and last write time, as FILETIME structures
you can use SetTimer/WM_TIMER to generate periodic checks
ReadDirectoryChangesW (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v=vs.85%29.aspx)
didn't know about that one :P
Interesting function, Sinsi. Thank you. :t
Gunther
FindFirstChangeNotification.
cman,
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365261(v=vs.85).aspx
Use:
invoke FindFirstChangeNotification, \
addr dirpath, \
FALSE, \
FILE_NOTIFY_CHANGE_FILE_NAME
I used this when I had a problem printing on a Win xp Pro computer from a DOS program. I had the DOS program "print" to a file instead of "LPT1" and monitored the directory for the creation of the file. Then used regular Win printing functions to print the file. I submitted an example called "NotifyPrint" but can't seem to find it.
hth,
farrier
morgot, also got it!
I found a short example (fasm syntax):
This would operate in a Thread, while your program does other stuff! Then is notified when a file change event occurs!
invoke FindFirstChangeNotification, \
addr pmpath, \
FALSE, \
FILE_NOTIFY_CHANGE_FILE_NAME
mov hPMNotify, eax
invoke WaitForSingleObject, hPMNotify, INFINITE
.while TRUE
DoYourFileChangeStuffHere:
invoke FindNextChangeNotification, hPMNotify
invoke WaitForSingleObject, hPMNotify, INFINITE
.endw
hth,
farrier