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.
I'm going the route of using system utilities to monitor a file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With