Module B0_std.Fpath
File paths.
A file system path specifies a file or a directory in a file system hierarchy. It is made of three parts:
- An optional, platform-dependent, volume.
- An optional root directory separator
dir_sepwhose presence distiguishes absolute paths ("/a") from relative ones ("a") - A non-empty list of
dir_sepseparated segments. Segments are non empty strings except for maybe the last one. The latter syntactically distiguishes directory paths ("a/b/") from file paths ("a/b").
The paths segments "." and ".." are relative path segments that respectively denote the current and parent directory. The basename of a path is its last non-empty segment if it is not a relative path segment or the empty string otherwise (e.g. on "/").
Separators and segments
val dir_sep_char : chardir_sep_charis the platform dependent natural directory separator. This is / on POSIX and \ on Windows.
val dir_sep : stringdir_sepisdir_sep_charas a string.
val is_seg : string -> boolis_seg sistrueiffsdoes not contain adir_sepor a null byte.
Paths
val v : string -> tv sis the stringsas a path.Warning. In code only use
"/"as the directory separator even on Windows platforms (don't be upset, the module gives them back to you with backslashes).- raises Invalid_argument
if
sis not a valid path. Useof_stringto deal with untrusted input.
val add_seg : t -> string -> tadd_seg p segifp's last segment is non-empty this ispwithsegadded. Ifp's last segment is empty, this ispwith the empty segment replaced byseg.- raises Invalid_argument
if
is_seg segisfalse.
Directory paths
Note. The following functions use syntactic semantic properties of paths. Given a path, these properties can be different from the ones your file system attributes to it.
val is_dir_path : t -> boolis_dir_path pistrueiffpsyntactically represents a directory. This means thatpis.,..or ends with/,/.or/...
Basename and parent directory
Note. The following functions use syntactic semantic properties of paths. Given a path, these properties can be different from the ones your file system attributes to it.
val basename : t -> stringbasename pis the last non-empty segment ofpor the empty string otherwise. The latter occurs only on root paths and on paths whose last non-empty segment is a relative segment.
val parent : t -> tparent pis a directory path that containsp. Ifpis a root path this ispitself. Ifpis in the current directory this is./.
Predicates and comparison
val is_rel : t -> boolis_rel pistrueiffpis a relative path, i.e. the root directory separator is missing inp.
val is_abs : t -> boolis_abs pistrueiffpis an absolute path, i.e. the root directory separator is present inp.
val is_root : t -> boolis_root pistrueiffpis a root directory, i.e.phas the root directory separator and a single, empty, segment.
val is_current_dir : t -> boolis_current_dir pistrueiffpis either"."or"./".
val is_parent_dir : t -> boolis_parent_dir pistrueiffpis either".."or"../".
File extensions
The file extension (resp. multiple file extension) of a path segment is the suffix that starts at the last (resp. first) occurence of a '.' that is preceeded by at least one non '.' character. If there is no such occurence in the segment, the extension is empty. With these definitions, ".", "..", "..." and dot files like ".ocamlinit" or "..ocamlinit" have no extension, but ".emacs.d" and "..emacs.d" do have one.
val get_ext : ?multi:bool -> t -> extget_ext pisp's basename file extension or the empty string if there is no extension. Ifmultiistrue(defaults tofalse), returns the multiple file extension.
val has_ext : ext -> t -> boolhas_ext ext pistrueiffString.equal (get_ext p) e || String.equal (get_ext ~multi:true p) e.
Converting
val of_string : string -> (t, string) Stdlib.resultof_string sis the stringsas a path. The following transformations are performed on the string:- On Windows any / (
0x2F) occurence is converted to \ (0x5C)
An error returned if
sis""or if it contains a null byte. The error string mentionss.- On Windows any / (
val to_string : t -> stringto_string pis the pathpas a string. The result can be safely converted back withv.
val conv : t Conv.tconvconverts file paths. The textual representation uses non-empty atoms. See alsoconv_only.
val conv_only : t Conv.tconv_onlyconverts file paths. Textual conversion is not composable, useconvinstead. Textual encoding pass the string as is and decoding ignores the initial starting point and parses the whole input string into a file path.
val dump : t Fmt.tdump ppf pprints pathponppfusingString.dump.
Uniqueness
Paths map and sets
type path= t
module Set : sig ... endPath sets.
module Map : sig ... endPath maps.
Search paths
A search path is a list of paths separated by a designated separator. A well known search path is PATH in which executable binaries are looked up.
val search_path_sep : stringsearch_path_sepis the default platform specific separator for search paths, this is";"ifSys.win32 istrueand":"otherwise.
val list_of_search_path : ?sep:string -> string -> (t list, string) Stdlib.resultlist_of_search_path ~sep sparsessepseparated file paths froms.sepis not allowed to appear in the file paths, it defaults tosearch_path_sep. The order in the list matches the order from left to right ins.