Module Filename_extended
Extensions to Core.Core_filename.
val normalize : string -> stringnormalize pathRemoves as much "." and ".." from the path as possible. If the path is absolute they will all be removed.
val parent : string -> stringparent pathThe parent of the root directory is the root directory- returns
the path to the parent of
path.
val make_relative : ?to_:string -> string -> stringmake_relative ~to_:src freturnsfrelative tosrc.- raises Failure
if
is_relative f <> is_relative src
val make_absolute : string -> stringmake_absolute srcTurnsrcinto an absolute path expanded from the current working directory.
val expand : ?from:string -> string -> stringexpandMakes a path absolute and expands~~usernameto home directories. In case of error (e.g.: path home of a none existing user) raisesFailurewith a (hopefully) helpful message.
val compare : string -> string -> intFilename.compare is a comparison that normalizes filenames ("./a" = "a"), uses a more human ready algorithm based on
String_extended.collate("rfc02.txt > rfc1.txt") and extenstions ("a.c" > "a.h").It is a total comparison on normalized filenames.
val with_open_temp_file : ?in_dir:string -> ?write:(Stdlib.out_channel -> unit) -> f:(string -> 'a) -> string -> string -> 'awith_open_temp_file ~write ~f prefix suffixcreate a temporary file; runswriteon itsout_channeland thenfon the resulting file. The file is removed oncefis done running.
val with_temp_dir : ?in_dir:string -> string -> string -> f:(string -> 'a) -> 'aRuns
fwith a temporary dir as option and removes the directory afterwards.
val is_parent : string -> string -> boolis_parent dir1 dir2returnstrueifdir1is a parent ofdir2Note: This function is context independent, use
expandif you want to consider relatives paths from a given point.In particular:
- A directory is always the parent of itself.
- The root is the parent of any directory
- An absolute path is never the parent of relative one and vice versa.
"../../a"is never the parent of"."even if this could be true given form the current working directory.