title: inotify recursively how to do it?
body: <p>i need to print events on a folder with multiple subfolders. how to do it recursivly? Please print a c++ code. I am stucked!! Every time the evet is poped i need to open the subfolder, take the file and copy it into another directory. I don't want to list all the subfolders in every 2 seconds and find the files if there are any. Is not efficient. I need to use a monitor folder. Please help</p>
  
  <p>The director that i want to monitor has multiple subfolders. Each subfolder has another subfolder that could contain in a moment of time a file. MainFolder->Subfolders->each subfolder-> subfolder -> file.</p>
  
  <p>Here is the code I have for he moment:</p>
  
  <pre><code>/*
  
  
  */
    #include &lt;pthread.h&gt;
      #include &lt;unistd.h&gt;
  
  #include &lt;iostream&gt;
  #include &lt;sys/inotify.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/inotify.h&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
      #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;pthread.h&gt;
  using namespace std;
   vector&lt;string&gt; SS;
  
  
  
  void *print_message_function( void *ptr );
  
  
  int main(int argc, char **argv ){
  
    pthread_t t1;
      int fd,fd1,wd,wd1,i=0,i1=0,len=0,len1=0;
        int length;
      char pathname[100],buf[1024],buf1[1024];
     int data;
      struct inotify_event *event;
       char *message1 = "Thread 1";
  
  
  
     FILE *fr;
     // fd=inotify_init1(IN_NONBLOCK);//--rewrite
      fd = inotify_init();
  
  
      /* watch /test directory for any activity and report it back to me */
      wd=inotify_add_watch(fd,"/home/MainFoder/",IN_ALL_EVENTS);
  
    //  int flag=0;
     // char*ev="";
  //wd=inotifytools_watch_recursively_with_exclude("/home/MainFolder/",IN_ALL_EVENTS);
   while(1)
  {
  //sleep(30);
          //read 1024  bytes of events from fd into buf
  
  i=0;
          len=read(fd,buf,1024);
          while(i&lt;len){
  
              event=(struct inotify_event *) &amp;buf[i];
  
  
      /* watch /test directory for any activity and report it back to me */
  
  
              /* check for changes */
                {
              if((event-&gt;mask &amp; IN_OPEN) ||(event-&gt;mask &amp; IN_CREATE))
  
               {  
  
  
                   printf("\n %s :was opened\n",event-&gt;name);
                  SS.push_back(event-&gt;name);
  
  
  
               }
  
         }
              /* update index to start of next event */
              i+=sizeof(struct inotify_event)+event-&gt;len;
          }
  
           vector&lt;string&gt;::const_iterator cii;
  for(cii=SS.begin(); cii!=SS.end(); cii++)
         {
  
  
  wd1 = watch_from_filename(*ci);
  }
  /*
  vector&lt;string&gt;::const_iterator cii;
         for(cii=SS.begin(); cii!=SS.end(); cii++)
         {
            cout &lt;&lt;"HERE:"&lt;&lt; *cii &lt;&lt; endl;
         }
  */
  int  iret1, iret2;
  
      /* Create independent threads each of which will execute function */
  
       iret1 = pthread_create( &amp;t1, NULL, print_message_function, (void*) message1);
  
  }
  
  }
  void *print_message_function( void *ptr )
  {
      vector&lt;string&gt;::const_iterator cii;
         for(cii=SS.begin(); cii!=SS.end(); cii++)
         {
  
            cout &lt;&lt;"HERE:"&lt;&lt; *cii &lt;&lt; endl;
            std::string path=exec
  
         }
  }
  </code></pre>