Skip to content

Commit 2146c8a

Browse files
authored
Merge pull request #730 from talex5/fs-example
Add examples/fs showing how to walk a directory tree
2 parents d834d73 + 7d71840 commit 2146c8a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

examples/fs/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(executable
2+
(name main)
3+
(libraries eio_main))

examples/fs/main.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(* Walks the directory tree rooted at the current directory,
2+
displaying all directory names (skipping hidden directories and `_build`). *)
3+
4+
open Eio.Std
5+
6+
let ( / ) = Eio.Path.( / )
7+
8+
let rec scan t =
9+
match Eio.Path.kind ~follow:false t with
10+
| `Directory ->
11+
traceln "Visiting %a" Eio.Path.pp t;
12+
Eio.Path.read_dir t |> List.iter (function
13+
| "_build" -> ()
14+
| item when String.starts_with ~prefix:"." item -> ()
15+
| item -> scan (t / item)
16+
)
17+
| _ -> ()
18+
19+
let () =
20+
Eio_main.run @@ fun env ->
21+
scan (Eio.Stdenv.cwd env)

0 commit comments

Comments
 (0)