Created
September 14, 2014 20:20
-
-
Save Leonidas-from-XIV/4fef0c4c01f485470c64 to your computer and use it in GitHub Desktop.
Deleting recursively using Lwt
This file contains hidden or 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
| 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