News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Detecting Change In Directory Contents

Started by cman, September 30, 2014, 03:08:06 AM

Previous topic - Next topic

cman

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.

dedndave

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


dedndave


Gunther

Interesting function, Sinsi. Thank you.  :t

Gunther
You have to know the facts before you can distort them.

morgot

Sorry for the bad English

farrier

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!

farrier

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