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

I want to know when a new file is created in a specific directory, and not scan the directory from time to time.

I understand that there is a way to get the operating system to inform my program that a new file has been created. How it works?

As already noted, this is similar to How to get notified of a file / directory change in C / C ++, ideally using POSIX

+6
linux windows file operating-system
source share
8 answers

Depends on which OS.

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

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

To add to OS X's answer starting at 10.5 you want the FSEvents API .

+16
source share

On Linux, check out Inotify .

+7
source share

How to get notified of a file / directory change in C / C ++, ideally using POSIX

or do an inotify search on stackoverflow, you will get many ideas

+4
source share

FAM provides a consistent file browsing interface on all UNIX. On Linux, the background daemon can be replaced with Gamin , but the FAM-related program will work just fine with Gamin. (Behind the scenes, FAM can use polling, and Gamin can use inotify or dnotify or kqueue, but you don't need to worry about that.)

OS X.5 has FSEvents , which is very different in that it controls the entire system instead of the specified files and directories, but will also satisfy your needs.

On Windows, see Find (first | Next | Close) Change Notification or ReadDirectoryChanges .

+3
source share

FileSystemWatcher is the answer - and it works recursively.

Here is an example here (search FileSystemWatcher)

+2
source share

Using .Net on Windows (not sure about Linux / mono), you can use FileSsytemWatcher to view new files and create events when they are created.

From MSDN:

Use FileSystemWatcher to view the change in the specified directory. You can monitor changes to files and subdirectories of the specified directory. You can create a component to view files on a local computer, a network drive, or a remote computer.

MSDN Page

+1
source share

On Mac OS X, this functionality is part of the Spotlight API.

+1
source share

The Windows API provides tools for monitoring the file system - here is an example http://msdn.microsoft.com/en-us/library/aa365261%28VS.85%29.aspx

+1
source share

All Articles