From: Jean Privat Date: Thu, 26 May 2016 23:55:15 +0000 (-0400) Subject: Merge: lib/core: Added `is_dir` function to `Path` X-Git-Url: http://nitlanguage.org?hp=263b33b7966567720a9957324f996fe73d42d3dc Merge: lib/core: Added `is_dir` function to `Path` Quite self-explanatory, really it is just a simpler `Path::stat` followed by a `FileStat::is_dir`. Pull-Request: #2128 Reviewed-by: Jean Privat --- diff --git a/lib/core/file.nit b/lib/core/file.nit index def1cd2..7f1d481 100644 --- a/lib/core/file.nit +++ b/lib/core/file.nit @@ -663,6 +663,19 @@ class Path return res end + # Is `self` the path to an existing directory ? + # + # ~~~nit + # assert ".".to_path.is_dir + # assert not "/etc/issue".to_path.is_dir + # assert not "/should/not/exist".to_path.is_dir + # ~~~ + fun is_dir: Bool do + var st = stat + if st == null then return false + return st.is_dir + end + # Delete a directory and all of its content # # Does not go through symbolic links and may get stuck in a cycle if there