-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples/fs showing how to walk a directory tree
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(executable | ||
(name main) | ||
(libraries eio_main)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |