Add Path.change_extension

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
This commit is contained in:
David Allsopp 2017-08-26 14:00:58 +01:00
parent a7406ab169
commit 9180f88dc3
2 changed files with 7 additions and 0 deletions

View File

@ -411,3 +411,7 @@ let rm_rf =
match Unix.lstat fn with
| exception Unix.Unix_error(ENOENT, _, _) -> ()
| _ -> loop fn
let change_extension ~ext t =
let t = try Filename.chop_extension t with Not_found -> t in
t ^ ext

View File

@ -101,3 +101,6 @@ val rmdir : t -> unit
val unlink : t -> unit
val unlink_no_err : t -> unit
val rm_rf : t -> unit
(** Changes the extension of the filename (or adds an extension if there was none) *)
val change_extension : ext:string -> t -> t