Skip to content

Commit

Permalink
Add examples/fs showing how to walk a directory tree
Browse files Browse the repository at this point in the history
  • Loading branch information
talex5 committed May 21, 2024
1 parent d834d73 commit 7d71840
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/fs/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name main)
(libraries eio_main))
21 changes: 21 additions & 0 deletions examples/fs/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(* Walks the directory tree rooted at the current directory,
displaying all directory names (skipping hidden directories and `_build`). *)

open Eio.Std

let ( / ) = Eio.Path.( / )

let rec scan t =
match Eio.Path.kind ~follow:false t with
| `Directory ->
traceln "Visiting %a" Eio.Path.pp t;
Eio.Path.read_dir t |> List.iter (function
| "_build" -> ()
| item when String.starts_with ~prefix:"." item -> ()
| item -> scan (t / item)
)
| _ -> ()

let () =
Eio_main.run @@ fun env ->
scan (Eio.Stdenv.cwd env)

0 comments on commit 7d71840

Please sign in to comment.