Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filechange c++

Status
Not open for further replies.

susuke

Technical User
Jul 22, 2002
17
0
0
HU
Hi!

I want to catch the changes of a file (time or size) in c++, but not with timer, i want to start a code automatically when the file is changed. Is there any possibilities for this in c++?
 
Sure thing.

Check out the documentation in MSDN regarding FindFirstChangeNotification


/Per
[sub]Nerdy signatures are as lame as the inconsistent stardates of STTNG.[/sub]
 
OK, but if i use this then i need a timer, what run this command cyclic, don't i? But i don't want to use timer. I imagine this like this:

the file changes -> an event activate -> run code.

I want that the code run when the file changes, but i don't want to check it from the program with timer...

(sorry, if you can't understand what i want to say, but my english is not so good...)
 
Did you check out the documentation I mentioned? I guess not, since there is nothing with timers there...
----------------------------------
Basic idea:
1)
You call FindFirstChangeNotification with some parameters/filters.

2)
Then you wait for the notifications to arrive, using WaitForSingleObject or WaitForMultipleObjects (if you for example want to listen changes in more than one directory).
You could put this in a while loop to keep on listening.
----------------------------------
Since your code will stand and wait it will "hang" your application.
Solution: Put the above mentioned stuff in a separate thread...

I reapeat, check out the articles in MSDN regarding FindFirstChangeNotification


/Per
[sub]Nerdy signatures are as lame as the inconsistent stardates of STTNG.[/sub]
 
You need to wrap your code into a service which is always 'up and running' - ready to receive the notification(s).

/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top