Skip to content

Commit

Permalink
Merge pull request #730 from talex5/fs-example
Browse files Browse the repository at this point in the history
Add examples/fs showing how to walk a directory tree
  • Loading branch information
talex5 authored May 21, 2024
2 parents d834d73 + 7d71840 commit 2146c8a
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 2146c8a

Please sign in to comment.