Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Created September 14, 2014 20:20
Show Gist options
  • Select an option

  • Save Leonidas-from-XIV/4fef0c4c01f485470c64 to your computer and use it in GitHub Desktop.

Select an option

Save Leonidas-from-XIV/4fef0c4c01f485470c64 to your computer and use it in GitHub Desktop.
Deleting recursively using Lwt
let rec rmtree path = lwt stat = Lwt_unix.lstat path in
match stat.Unix.st_kind with
| Unix.S_REG | Unix.S_LNK | Unix.S_BLK | Unix.S_CHR | Unix.S_SOCK | Unix.S_FIFO ->
Lwt_unix.unlink path
| Unix.S_DIR ->
Lwt_unix.files_of_directory path
|> Lwt_stream.filter (fun x -> x <> "." && x <> "..")
|> Lwt_stream.iter_s (fun p ->
let subdir = Filename.concat path p in
rmtree subdir)
>> Lwt_unix.rmdir path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment