Sign in to follow this  

File changes with ReadDirectoryChangesW()

This topic is 3596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all I'm listening for file changes with ReadDirectoryChangesW(), and all is well in the universe. The problem is, I get called back several times upon a single 'save' to a file. I can't figure how to differentiate between the alerts. All I care about is when the file is completed writing its changes. I tried to tell by fopen(), but that succeeds all the time, not just when the file is done writing. Any ideas? -programmer_tom

Share this post


Link to post
Share on other sites
Instead of using fopen, try using CreateFile with read and write exculsivity set.
This worked for me in a similar situation.
The solution isn't very neat and the "correct" way might be to enumerate all handles to the file and check if it's zero.
I don't know how to do that but there are some tools that can list all handles to a file so there must be a way.
Edit: I had a problem using this technique though.
Because one of the tools that was writing a file that I needed to´detect changes to and act upon did some stupid things like:
open(new), write, close, open(append), write, close, ....., open(append), write, close.
I don't know how to test for that sort of things (worse was that if I opened the file with exclusivity the program would crash because it couldn't open the file since it's been locked by my test :().

Share this post


Link to post
Share on other sites

This topic is 3596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this