# Lwt and directory changes

**URL:** <https://discuss.ocaml.org/t/lwt-and-directory-changes/12911>\
**Category:** Ecosystem\
**Tags:** lwt, filesystem\
**Created:** [August 27, 2023, 10:43am UTC](https://discuss.ocaml.org/t/lwt-and-directory-changes/12911 "2023-08-27T10:43:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zbroyar](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zbroyar/32/3789_2.png) [@zbroyar](https://discuss.ocaml.org/u/zbroyar)\
**Post date:** [August 27, 2023, 10:43am UTC](https://discuss.ocaml.org/t/lwt-and-directory-changes/12911/1 "2023-08-27T10:43:39Z")

</div>

Hi all,

I have a directory and need to get a notification when a new file appears in it.  
Any suggestions on how to do it with Lwt?

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![ahem](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ahem/32/1490_2.png) [@ahem](https://discuss.ocaml.org/u/ahem)\
**Post date:** [August 27, 2023, 2:02pm UTC](https://discuss.ocaml.org/t/lwt-and-directory-changes/12911/2 "2023-08-27T14:02:08Z")

</div>

I have used this library: [lwt-inotify](https://docs.ocaml.pro/docs/LIBRARY.inotify-lwt@inotify.2.3/Lwt_inotify/index.html) for similar purposes before. I don’t think that [inotify](https://man7.org/linux/man-pages/man7/inotify.7.html) has an event specifically for “only when a new file appears in a directory”, but maybe the [dune](https://github.com/ocaml/dune) code-base has some example code that does this (with async though).

---

<div class="post-metadata">

**Author:** ![zbroyar](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zbroyar/32/3789_2.png) [@zbroyar](https://discuss.ocaml.org/u/zbroyar)\
**Post date:** [August 29, 2023, 10:00pm UTC](https://discuss.ocaml.org/t/lwt-and-directory-changes/12911/3 "2023-08-29T22:00:37Z")

</div>

Thanks! It’s exactly what I was looking for.

---

<div class="post-metadata">

**Author:** ![avsm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/avsm/32/6_2.png) [@avsm](https://discuss.ocaml.org/u/avsm)\
**Post date:** [August 30, 2023, 4:44pm UTC](https://discuss.ocaml.org/t/lwt-and-directory-changes/12911/4 "2023-08-30T16:44:01Z")

</div>

Note that inotify is Linux only; if you need something more portable (but also more complex), then Irmin has a [irmin-watcher](https://github.com/mirage/irmin-watcher) library that supports inotify (Linux), fsevents (macOS) and a polling mode (Windows/other).

---

<div class="post-metadata">

**Author:** ![zbroyar](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zbroyar/32/3789_2.png) [@zbroyar](https://discuss.ocaml.org/u/zbroyar)\
**Post date:** [August 31, 2023, 8:41pm UTC](https://discuss.ocaml.org/t/lwt-and-directory-changes/12911/5 "2023-08-31T20:41:40Z")

</div>

Thanks.

I don’t need portability right now but it definitely worth a careful look.
