Page
Library
Module
Module type
Parameter
Class
Class type
Source
Virtfs.PathA path Path.t is a lax representation of a file path in an abstract file system. It can be used to describe, abstractly, operations on file paths and to mock file systems.
The library does not focus on the correctness of paths, but aims to provide a simple and composable API for quickly expressing file paths in systems that abstract the execution target (e.g. in YOCaml).
Unlike Fpath, there is no distinction (in terms of representation) between directories and files.
The API is generally pure, which explains why when we talk about "changing a path", moving it, etc., we are referring to calculating a new path; no operations are performed on the disk.
val abs : string list -> tabs ["foo"; "bar"] builds the path "/foo/bar".
val rel : string list -> trel ["foo"; "bar"] builds the path "./foo/bar".
val root : troot is the root of the file system "/".
val cwd : tcwd is the current working directory "./".
dirname p returns the parent of p. The parent of root is root and the parent of cwd is "../".
val basename : t -> stringbasename p returns the basename of p. The basename of root is "/" and the basename of cwd is ".".
val basename_opt : t -> string optionbasename_opt p returns the basename of p. The basename of root and cwd is None.
Set of functions that enable the description of path movements.
move ~into source calculate the path corresponding to the movement from path source to path into.
relocate ?strategy ?ignore_kind ~into source is like move, but relocates the full source path instead of only its basename.
With `Merge (default), overlapping suffixes are merged:
# open Virtfs.Path ;;
# (rel [ "bar"; "index.md" ])
|> relocate ~into:(rel [ "foo"; "bar"; "baz" ])
|> to_string ;;
- : string = "./foo/bar/index.md"With `Force, source is appended as-is into into.
If into and source have different kinds (Relative vs Absolute), `Force is applied unless ignore_kind is true.
rename ?preserve_extension ~new_name p calculate a new name for the given path p. The flag preserve_extension describes a strategy for preserving the extension of the source p. If it is not passed, the extension is ignored.
`Ext preserves the extension of the source (see extension)`Compound preserves the extension of the source (see compound_extension)trim ?ignore_kind ~prefix p will remove the given prefix from the given path p. If the paths have different kinds (absolute vs relative), their prefixes are incompatible, unless the ignore_kind flag is set to true (and use the p kind as a main kind).
resolve ~from p will resolve p from from's perspective. If p is absolute, it return p.
scope ~from p will share the scope of from and p. It is resolve ~from:(dirname from).
Dealing with file extensions. Since the library does not assume whether a file is a file or a directory, the functions generally work.
An extension (returned) is always prefixed with a ".".
val extension : t -> stringextension p returns the extension for the given path p. If the path has no extension, it returns an empty string.
val extension_opt : t -> string optionextension_opt p is like extension but wrap the result into an option. So if a path has no extension, it returns None.
val compound_extension : t -> string listcompound_extension p returns the list of compound extension for the given path p.
val has_extension : string -> t -> boolhas_extension ext p returns true if the path p has the extension ext. (It works on compound extension)
val has_any_extension : string list -> t -> boolhas_any_extension exts p returns true if the path p has one of the extensions in exts. (It works on compound extension)
remove_extension ?kind p remove the extension of the given p. The kind can change the extension removal strategy:
`Compound Removes the compound extension.`Ext str Remove the given extension.replace_extension ?kind ext p replace the extension of p by ext (the previous extension is removed using remove_extension) using the given kind).
change_extension is replace_extension.
Predicates on file paths.
val is_absolute : t -> boolis_absolute p returns true if p is defined as an absolute path, false otherwise.
val is_relative : t -> boolis_relative p returns true if p is defined as a relative path, false otherwise.
val is_root : t -> boolis_root p returns true if the path p seems to point "/".
val is_cwd : t -> boolis_cwd p returns true if the path p seems to point "./".
compare p1 p2 returns 0 if p1 is equal to p2, a negative integer if p1 is less than p2, and a positive integer if p1 is greater than p2. It is always assumed that a relative path is shorter than an absolute path then the lexicographical order is chosen.
val to_filename : t -> stringto_filename p returns the filename representation of the path p using Filename constants.
val to_string : t -> stringto_string p returns the representation of the path p.
val from_string : string -> tfrom_string s returns a path from the given string s.
val of_string : string -> tof_string is from_string - consistent with the OCaml ecosystem.
val fragments : t -> string listfragments p returns the list of segments/fragments for a given path p.
A set of infix operators.
module Infix : sig ... end