C++ - polling directories every few minutes

Get help on programming - C++, Java, Delphi, etc.
Post Reply
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

C++ - polling directories every few minutes

Post by Ron2K »

Hi,

I'm attempting to write a C++ application that has to keep a watch on certain directories (by polling them every minute or 2). Any idea on how I would do this? My MSDN and Google searches weren't very helpful.
Kia kaha, Kia māia, Kia manawanui.
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

C++ flavour?
Image
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Post by Ron2K »

Visual C++ (2005)
Kia kaha, Kia māia, Kia manawanui.
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

I take it you're not using the .NET Framework for this?
Image
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Post by Ron2K »

No.
Kia kaha, Kia māia, Kia manawanui.
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

OK, I have only done it in .NET.

In Native apps you're going to have to use the API to get a directory listing, and then you can compare it to a saved list.

OR

Just make sure that after you've processed a file, delete it from the directory, so that you know that any files in the directory have to be processed.

I don't know the exact API calls though, so I can't be much help there now.
Image
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

I don't think you will just find something specific to your question.

You gonna have to manually think of a solution.

First of all the poll interval find a way to code a loop interval in a sperate thread
Then why not google on something that retrieves the contents of a folder structure with the files in it, go with dates (modified, created ect)

I think in c++ there is a scandir command or something that allowes you to do it.
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Post by Ron2K »

Thanks for the suggestions - I just found something, and I'm on to it...
Kia kaha, Kia māia, Kia manawanui.
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

You can take care of the polling action through multithreading, and an endless while loop.

Simply Start a new worker thread that runs through an endless loop and then sleep it when there is no work to do, untill the next poll.
Image
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Post by Ron2K »

This is what I've decided to use - after some more searching, I found an article on using timers with the MFC:

http://www.functionx.com/visualc/controls/timer.htm

Now, I'm going to activate the timer, and every time it sends the WM_TIMER message I'll check the directory.

Thanks for all the suggestions though.
Kia kaha, Kia māia, Kia manawanui.
Post Reply