package topkg

  1. Overview
  2. Docs

File operations.

Famous file paths

val null : fpath

null represents a file on the OS that discards all writes and returns end of file on reads.

val dash : fpath

dash is "-". This value is is used by read and write to respectively denote stdin and stdout.

Existence and deletion

val exists : fpath -> bool result

exists file is true if file is a regular in the file system and false otherwise. Symbolic links are followed.

val must_exist : fpath -> fpath result

must_exist file is file if file is a regular file in the file system and an error otherwise. Symbolic links are followed.

val delete : ?must_exist:bool -> fpath -> unit result

delete ~must_exist file deletes file file. If must_exist is true (defaults to false) an error is returned if file doesn't exist.

Folding over file hierarchies

val fold : ?skip:(fpath -> bool) -> (fpath -> 'a -> 'a) -> 'a -> fpath list -> 'a result

fold_files skip f acc paths folds f over the files found in the file hierarchies starting at paths. Files and directories p for which skip p is true are skipped. skip defaults to (fun _ -> false).

Reading and writing

val read : fpath -> string result

read file is file's contents. If file is dash reads from Pervasives.stdin and the channel is not closed when the function returns.

val write : fpath -> string -> unit result

write file content writes content to file. If file is dash writes to Pervasives.stdout and flushes but doesn't close the channel when the function returns.

Temporary files

val tmp : unit -> fpath result

tmp () creates a temporary file and returns its name. The file is destroyed at the end of program execution.

OCaml

Innovation. Community. Security.