Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7182411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:45:55+00:00 2026-05-28T17:45:55+00:00

I have a folder called Datas. This folder has a subfolder called Inbox inside

  • 0

I have a folder called “Datas”. This folder has a subfolder called “Inbox” inside of which there are multiple “.txt” files. This “Datas” folder can be modified and in the end there will be multiple subfolders with “Inbox” subfolders and “.txt” files. I need to monitor the “Datas” folder and the “.txt” file from the “Inbox” folder. How can I do that?

INotify is just monitoring a folder and pops events when subfolders are created. How to pop events when “.txt” files are created (in which folder)?

I need C or C++ code but I am stuck. I do not know how to solve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:45:56+00:00Added an answer on May 28, 2026 at 5:45 pm

    From the inotify manpage:

       IN_CREATE         File/directory created in watched directory (*).
    

    It can be done by catching this event.

    Again from the manpage:

      Limitations and caveats
           Inotify  monitoring  of  directories  is  not recursive: to monitor subdirectories under a directory, additional watches must be created.  This can take a significant
           amount time for large directory trees.
    

    So, you will need to do the recursive part yourself. You can start by looking an example from here. You should also have a look at the project notify-tools

    EXAMPLE as asked in comments: It monitors /tmp/inotify1 & /tmp/inotify2 for new files created & displays the events

    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/inotify.h>
    
    #define EVENT_SIZE  ( sizeof (struct inotify_event) )
    #define BUF_LEN     ( 1024 * ( EVENT_SIZE + 16 ) )
    
    int main( int argc, char **argv ) 
    {
        int length, i = 0;
        int fd;
        int wd[2];
        char buffer[BUF_LEN];
    
        fd = inotify_init();
    
        if ( fd < 0 ) {
            perror( "inotify_init" );
        }
    
        wd[0] = inotify_add_watch( fd, "/tmp/inotify1", IN_CREATE);
        wd[1] = inotify_add_watch (fd, "/tmp/inotify2", IN_CREATE);
    
        while (1){
            struct inotify_event *event;
    
            length = read( fd, buffer, BUF_LEN );  
    
            if ( length < 0 ) {
                perror( "read" );
            } 
    
            event = ( struct inotify_event * ) &buffer[ i ];
    
            if ( event->len ) {
                if (event->wd == wd[0]) printf("%s\n", "In /tmp/inotify1: ");
                else printf("%s\n", "In /tmp/inotify2: ");
                if ( event->mask & IN_CREATE ) {
                    if ( event->mask & IN_ISDIR ) {
                        printf( "The directory %s was created.\n", event->name );       
                    }
                    else {
                        printf( "The file %s was created.\n", event->name );
                    }
                }
            }
        }
        ( void ) inotify_rm_watch( fd, wd[0] );
        ( void ) inotify_rm_watch( fd, wd[1]);
        ( void ) close( fd );
    
        exit( 0 );
    }
    

    Test run:

    shadyabhi@archlinux ~ $ ./a.out 
    In /tmp/inotify1: 
    The file abhijeet was created.
    In /tmp/inotify2: 
    The file rastogi was created.
    ^C
    shadyabhi@archlinux ~ $
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder called Etc which has an image I want to use
I have 2 images inside a folder called Pics..... Image1.jpg and Image2.jpg. What code
say that i have a project which lies in a folder called 'bin', and
I have a dvd copied in my hard drive. It has a folder called
I have a folder, called files. It's already in the repository. Now, new files
I have a file called 34.php?session=2534464a39a2c97cb7113689726a4e52 in my /var/www/html folder but I can't view
I have folder home/admin. In this folder there is index.php. When i access to
I have a file called config.yml in my /config folder of my rails application.
I have a foler called A and inside A, i have 2 folders B
I have a folder on my server to which I had a number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.