1

I have a directory by the name of Container which contains the demo.txt file. I am monitoring this Container directory and accessing this demo.txt file but if I copied a new file and tried to access it, I will also have to change the pathname/filename.

I want to automate this process. It means if the new file is added to the Container directory then it should check it automatically without having to give the filename every time. Because so many files are continuously adding every time.

Is it possible this way?

int main(){
    if(access("home/Container/demo.txt", F_OK ) != -1){
        printf("This file already exists in Container");
    }
    else{
        printf("This file does not exist");
    }
    return 0;
}
Bum bum
  • 19
  • 2
  • Does this answer your question? [How to list files in a directory in a C program?](https://stackoverflow.com/questions/4204666/how-to-list-files-in-a-directory-in-a-c-program) – TSG Jan 06 '21 at 17:02
  • 1
    This question boils down to this: you require a way to list files in a directory, and then you will be able to check when this changes. See this related question: https://stackoverflow.com/questions/4204666/how-to-list-files-in-a-directory-in-a-c-program/17683417 – TSG Jan 06 '21 at 17:03
  • How do you know what files are "new" when this process starts after it's been down for a while? Using the filesystem as a message queue like you're trying to do here is usually a really bad idea. You're trying to use a state-saving device as an event detector. – Andrew Henle Jan 06 '21 at 17:04

0 Answers0