Boost logo

Boost Users :

Subject: Re: [Boost-users] file monitoring
From: SRD (software.research.development_at_[hidden])
Date: 2013-04-08 19:04:09


Thank you for the suggestions. So after looking over the ASIO extension, I
have basically this implemented in my project and though I see a change
when I add a file to the directory being monitored, I see no futher
changes.

I'm trying to monitor a directory and when a file is added, I will then
make mods to it and move it elsewhere. I'm new to boost, and my
understanding is that this is being executed within a thread, and it acts
like its blocking.

Any help much appreciated.

void create_file_handler(const boost::system:error_code &ec,
    const boost::asio::dir_monitor_event &ev)
{
    cout << "file name: " << ev.filename << endl;
    cout << " type : " << ev.type << endl;

    // now edit file ...
}

        // from main()

        boost::thread t;

        {
            boost::asio::io_service io_service;
            boost::asio::dir_monitor dm(io_service);

            dm.add_directory("C:\\Users\\SRD\\DirA");

            boost::asio::dir_monitor_event ev = dm.monitor();
            dm.async_monitor(create_file_handler);

            t = boost::thread(boost::bind(&boost::asio::io_service::run,
boost::refio_service)));
            boost::system_time time = boost::get_system_time();
            time += boost::posix_time::time_duration(0, 0, 1);
            boost::thread::sleep(time);
        }

        t.join();
        io_service.reset();

        // now do app stuff ..

On Fri, Apr 5, 2013 at 4:39 PM, Boris Schaeling <boris_at_[hidden]> wrote:

> On Fri, 05 Apr 2013 00:19:51 +0200, SRD <software.research.**
> development_at_[hidden] <software.research.development_at_[hidden]>> wrote:
>
> I'm looking for a way to get notified as soon as a new file has been
>> created. So I was wondering if boost has a way of monitoring files so
>> I can send them off as soon as I receive them. This would have to work
>> for Linux and windows. I saw a few posts which seem to indicate that
>> its not there yet, but that was some time ago.
>>
>
> If you click on http://en.highscore.de/cpp/**boost/asio.html>and scroll down to the very end, you find a directory monitor. It's a
> Boost.Asio I/O service object I once created. I don't remember whether it
> does out of the box what you need. But then feel free to adapt it. :)
>
> HTH,
> Boris
>
>
> ______________________________**_________________
> Boost-users mailing list
> Boost-users_at_[hidden]
>
http://lists.boost.org/**mailman/listinfo.cgi/boost-**users>
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net