Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D Lang File Watcher

Tags:

d

I'm new to D Language and am looking for an efficient way to watch for a specific file to change.

Ultimately what I'd like is to have a watcher that waits for a file to change, and then executes a command based on the contents of the file (think of it as a plain-text queue list).

Code samples would be nice, but pointing me in the right direction would also be very helpful.

Also, this is going to run on a Linux environment.

Update

I'm going the route of using system utilities to monitor a file.

like image 360
kmatheny Avatar asked Feb 20 '23 01:02

kmatheny


1 Answers

If you're on Linux you can use inotify, found in /usr/include/sys/inotify.h (on my system $PREFIX might differ).

inotify is very useful in many situations where reactions on file system changes are necessary. Without inotify it can be implemented by periodical (or manually requested) examining files and directories. But such way is slow and wastes processor time. inotify brings very fast and economical method how to react on file system changes.

The only thing you have to do is translating this header into a "D header", or you use DStep which might be able to translate the header for you.

You might also want to use fanotify, a newer replacement for inotify.

Unfortunatly I don't know how you can do that on Windows, all I found is a Windows-API function: FindFirstChangeNotification

like image 198
dav1d Avatar answered Feb 27 '23 18:02

dav1d