title: inotify get directory
body: <p>I want to monitor the creation of new files in some directories and read this link about <a href="http://www.linuxforu.com/2011/04/getting-started-with-inotify/" rel="nofollow noreferrer">inotify</a>. I liked the implementation and used it. However, in my case, I want to monitor a directory which has up to level-3 sub-dirs.</p>
  <p>My thought is to add a watch each time a new directory is created, but in order to do this, I need to know the path of the created directory. Unfortunately, the event struct of <code>inotify</code> can give me only the name of the file-directory created and not its path. Can anyone suggest an idea for this?</p>
  <pre><code>add_watch(fd,root);
    if ( event-&gt;mask &amp; IN_CREATE) {
          if (event-&gt;mask &amp; IN_ISDIR){
            printf(&quot;%d DIR::%s CREATED\n&quot;, event-&gt;wd,event-&gt;name );
            strcpy(new_dir,root);
            strcat(new_dir,&quot;/&quot;);
            strcat(new_dir,event-&gt;name);
            add_watch(fd,new_dir);
  </code></pre>
  <p>where add_watch is :</p>
  <pre><code>void add_watch(int fd, char *root)
    {
    int wd;
    struct dirent *entry;
    DIR *dp;
  
    dp = opendir(root);
    if (dp == NULL)
    {
    perror(&quot;Error opening the starting directory&quot;);
    exit(0);
    }
  
    /* add watch to starting directory */
    wd = inotify_add_watch(fd, root, IN_CREATE | IN_MODIFY | IN_MOVED_TO);
  </code></pre>
  <p>This is ok for the root directory,the level-1 sub-dir gets watched also,but when i try to add a watch to the level-2 sub-dir the path is not right.</p>
  <p>writing in c++ with netbeans7.2,ubuntu12.</p>