Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need a logic for checking the directory for a file if a file exists i need to store the file name to a variable

for example:-

i am having a directory called "test", initially it is empty, i need to continuously check this directory for a file if any file is present in the directory for eg: if it contains "name.txt"
file
i need to store this name to a variable like below

char *buff;
buff = name.txt;



can any plz suggest any idea, i have a logic for checking the directory but i do know how to take a filename and to store that in a variable

Thanks
shan
Posted

This thread[^] contains some ideas specifically for C (not C++)
 
Share this answer
 
Use the inotify API[^] to continuously monitor the directory. The inotify event structure contains a file name you can copy to your own variable with strncpy() after allocating a sufficiently large buffer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900