If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to detect a new file

I'm trying to write a program that will look in a couple of directories for new files to appear. I currently have two threads that poll in their respective directories for files, then Sleep() for 5 seconds and check again. For some reason, this method uses up almost all of the CPU time
I read a post in this forum yesterday that used FindFirstChangeNotification and WaitForMultipleObjects to search two directories that I was hoping wouldn't use up the CPU, but I can't figure out the search string that I used to find it
Could some please give me an example of how to do this, or point me to the thread that gave this example?

Thanks.

------------------------------------------------------
There are only 10 types of people in the world.
Those who understand binary and those that don't.

I have a thread that does the same thing, but I search every 17.5 sec's and have little cpu useage. How many files do you have in the dir and what function are you using to get the file names??

Jim
ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

"The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

"Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

I have a thread that does the same thing, but I search every 17.5 sec's and have little cpu useage. How many files do you have in the dir and what function are you using to get the file names??

Both of the directories don't have any files in them (until they appear from a external source, of course).
I'm using FindFirstFile() and FindNextFile(). I think I might be getting constant hits on '.' and '..', would ReadDirectoryChangesW() overlook those?

------------------------------------------------------
There are only 10 types of people in the world.
Those who understand binary and those that don't.

"The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

"Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

I read a post in this forum yesterday that used FindFirstChangeNotification and WaitForMultipleObjects to search two directories that I was hoping wouldn't use up the CPU, but I can't figure out the search string that
Thanks.

There is a technical reason behind why you cannot find FindFirstChangeNotification under the CG search, it has to do with the length of the indexed word. I will start the discussion on this issue for you and see if the powers that be can bump the number up

for now, try a search engine like google and plug in CG in the search, you should be able to find the CG thread where you saw the code posted in the results returned.