Module Os.Path
File system path operations.
These functions operate on files and directories equally. Specific function operating on either kind of path are in the File and Dir modules.
Existence
val exists : Fpath.t -> (bool, string) Stdlib.resultexists pisOk trueifpexists in the file system andOk falseotherwise. Symbolic links are followed.
val must_exist : Fpath.t -> (unit, string) Stdlib.resultmust_exist pisOk ()ifpexists in the file system and an error otherwise. Symbolic links are followed.
Deleting and renaming
val delete : recurse:bool -> Fpath.t -> (bool, string) Stdlib.resultdelete ~recurse pdeletespfrom the file system. Ifpis a symbolic link this only deletes the link, not the linked object. Ifrecurseistrueandpis a non-empty directory, no error occurs, its contents is recursively deleted. The result is:Ok true, ifpexisted and was deleted.Ok false, if the pathpdid not exist on the file system.Error _in case of error, in particular ifpis a non-empty directory andrecurseisfalse.
See also
File.delete.
val rename : force:bool -> make_path:bool -> src:Fpath.t -> Fpath.t -> (unit, string) Stdlib.resultrename ~force ~make_path ~src dstrenamessrctodst.- If
forceistrueanddstexists it tries to delete it usingFile.deletedst. Ifforceisfalseanddstexists the function errors. - If
make_pathistrueand the parent directory ofdstdoes not exist the whole path to the parent is created as needed with permission0o755(readable and traversable by everyone, writable by the user).
- If
Copying
val copy : ?rel:bool -> ?atomic:bool -> ?allow_hardlinks:bool -> ?follow_symlinks:bool -> ?prune:(Unix.stats -> string -> Fpath.t -> bool) -> make_path:bool -> recurse:bool -> src:Fpath.t -> Fpath.t -> (unit, string) Stdlib.resultcopy ~make_path ~recurse ~src dstcopies the file or file hierarchy rooted atsrctodst. The function errors ifdstexists. The semantics and arguments correspond to those of Copying, except this function also works ifsrcis not a directory. Note thatpruneis never called onsrcitself FIXME is that a good idea ? also FIXME this should error ifsrcis a directory andrecurseis false.See also Copying and
Os.File.copy.
File mode and stat
See also File.is_executable.
val get_mode : Fpath.t -> (int, string) Stdlib.resultget_mode pis the file mode ofp. Symbolic links are followed.
val set_mode : Fpath.t -> int -> (unit, string) Stdlib.resultset_mode file psets the file mode offiletop. Symbolic links are followed.
val stat : Fpath.t -> (Unix.stats, string) Stdlib.resultstat pisp's file information. Symbolic links are followed.
Symbolic links
For hard links see Hard links.
val symlink : force:bool -> make_path:bool -> src:Fpath.t -> Fpath.t -> (unit, string) Stdlib.resultsymlink ~force ~src psymbolically linkssrctop.- If
forceistrueandpexists it tries to delete it usingFile.deletep. Ifforceisfalseandpexists the function errors. - If
make_pathistrueand the parent directory offiledoes not exist the whole path to the parent is created as needed with permission0o755(readable and traversable by everyone, writable by the user).
- If
val symlink_link : Fpath.t -> (Fpath.t, string) Stdlib.resultsymlink_link pisOk lifpis a symbolic link tol.
val symlink_stat : Fpath.t -> (Unix.stats, string) Stdlib.resultsymlink_stat pis likestatbut ifpis a symlink returns information about the link itself. Ifpis not a symlink then this isstat.
Temporary paths
type tmp_name= (string -> string, unit, string) Stdlib.formatThe type for temporary file name patterns. The string format is replaced by random hexadecimal US-ASCII characters.
val tmp : ?make_path:bool -> ?dir:Fpath.t -> ?name:tmp_name -> unit -> (Fpath.t, string) Stdlib.resulttmp ~make_path ~dir name ()is a file system path indirthat did not exist when the name was found. It may exist once the function returns though, prefer temporary files and directories creation functions to guarantee the creation of the temporary objects.nameis used to construct the filename of the file, seetmp_namefor details. It defaults to"tmp-%s".diris the directory in which the temporary file is created. It defaults toOs.Dir.default_tmp().- If
make_pathistrue(default) anddirdoes not exist the whole path to it is created as needed with permission0o755(readable and traversable by everyone, writable by the user).