Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the operating system tell me when a new file is created?

I want to know when a new file is created on a specific directory, instead of scanning the directory from time to time.

I understand that there is a way to make the operating system tell my program that a new file was created. How does it work?

As noted, this has similarities with How to be notified of file/directory change in C/C++, ideally using POSIX

like image 594
Liran Orevi Avatar asked May 01 '09 11:05

Liran Orevi


2 Answers

Depends on which OS.

On Windows, the base API would be Directory Change Notifications.

Since you mention Linux in the tags, this would be the inotify API.

To add to the OS X answer, as of 10.5, you want the FSEvents API.

like image 110
millimoose Avatar answered Oct 16 '22 01:10

millimoose


Under Linux, check out Inotify.

like image 36
Haakon Avatar answered Oct 16 '22 01:10

Haakon