CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2003
    Location
    Ridgecrest, CA
    Posts
    108

    Unhappy 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.

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    One possible solution is ReadDirectoryChangesW().

    Kuphryn

  3. #3
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539
    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.

  4. #4
    Join Date
    May 2003
    Location
    Ridgecrest, CA
    Posts
    108
    Quote Originally Posted by Vanaj
    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.

  5. #5
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539
    Are you looking for specific file extentions ?? or doing something like this ?


    Code:
    sprintf(szFullPathIn, "%s\\%s", pDlg->szPathIn, "*.QT");
    hFindFile = FindFirstFile(szFullPathIn, &lpFindFileData);
    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.

  6. #6
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Quote Originally Posted by mazeing
    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.

    google:
    findfirstchangenotification codeguru

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured