package ez_file

  1. Overview
  2. Docs
module OS = FileOS
module Sig = FileSig
include module type of struct include FileString end
include FileSig.FILE_OPERATIONS with type t := string
include FileSig.FILENAME_OPERATIONS with type t := string
val concat : string -> string -> string
val is_absolute : string -> bool
val is_relative : string -> bool
val is_implicit : string -> bool
val add_suffix : string -> string -> string
val check_suffix : string -> string -> bool
val extensions : string -> string list
val basename : string -> string
val dirname : string -> string
val add_basename : string -> string -> string
val add_basenames : string -> string list -> string
val chop_extension : string -> string
val last_extension : string -> string option
val current_dir_name : string
val open_in : string -> in_channel
val open_out : string -> out_channel
val open_in_bin : string -> in_channel
val open_out_bin : string -> out_channel
val open_fd : string -> MinUnix.open_flag list -> MinUnix.file_perm -> MinUnix.file_descr
val temp_file : string -> string -> string
val with_in : string -> (in_channel -> unit) -> unit
val with_in_bin : string -> (in_channel -> unit) -> unit
val with_out : string -> (out_channel -> unit) -> unit
val with_out_bin : string -> (out_channel -> unit) -> unit
val exists : string -> bool
val getcwd : unit -> string
val size : string -> int
val is_directory : string -> bool
val remove : string -> unit
val rename : string -> string -> unit
val stat : string -> MinUnix.stats
val lstat : string -> MinUnix.stats
module OP = FileString.OP
val copy_rec : string -> string -> unit
val uncopy_rec : string -> string -> unit
val find_in_path : string list -> string -> string

find_in_path path filename searches a file in a list of directories.

include FileSig.CONTENT_OPERATIONS with type in_file := string and type out_file := string
val read_file : string -> string

read_file file returns the full content of file. If the file is opened, it is opened in binary mode, no conversion is applied.

val write_file : string -> string -> unit

write_file file content creates file file with content content. If the file is opened, it is opened in binary mode, no conversion is applied.

val read_subfile : string -> int -> int -> string

read_subfile file pos len returns a string containing len bytes read from file file at pos pos. If the file is opened, it is opened in binary mode. Raises End_of_file if the file is too short.

val read_lines : string -> string array

read_lines file returns the content of file as an array of lines. If the file is opened, it is opened in text mode.

val read_lines_to_list : string -> string list

read_lines_to_list file returns the content of file as a list of lines. If the file is opened, it is opened in text mode.

val write_lines : string -> string array -> unit

write_lines file lines creates the file file from an array of lines, using FileChannel.output_line for each line.

val write_lines_of_list : string -> string list -> unit

write_lines file lines creates the file file from a list of lines, using FileChannel.output_line for each line.

val read_sublines : string -> int -> int -> string array

read_sublines file pos len returns at most len lines of the file file, starting at line pos. It differs from read_subfile in that it will not raise any exception if the file is too short. Note that it reads the file from beginning everytimes.

val read_sublines_to_list : string -> int -> int -> string list

Same as read_sublines, but returns a list of strings.

val iter_blocks : (EzCompat.Bytes.t -> int -> unit) -> string -> unit

iter_blocks f file reads the content of file file, and calls f buffer len on each chunk. The buffer is reused, and only the first len bytes are from the file. Chunks have a maximal size of 32768.

val iter_lines : (string -> unit) -> string -> unit

iter_lines f file calls f line on all the lines line of the file file.

val iteri_lines : (int -> string -> unit) -> string -> unit

iteri_lines f file calls f line_num line on every line line of the file file, with line_num the line number, starting with line 0.

val copy_file : string -> string -> unit

copy_file src dst copy all the content remaining in file src to file dst.

include FileSig.DIRECTORY_OPERATIONS with type t := string
exception NotADirectory of string

This exception is raised when one of the following functions is called with a non-directory argument

val make_dir : ?mode:int -> ?p:bool -> string -> unit

make_dir ?mode ?p filename creates a directory filename, if it does not already exist. It fails with NotADirectory if the file already exists, but is not a directory. The mode argument is the Unix permissions (0o755 by default). The p argument controls whether parents directories should be created as well, if they don't exist, instead of failing.

val remove_dir : ?all:bool -> ?glob:string -> string -> unit

remove_dir ?all filename removes directory filename, or complains the NotADirectory if it does not exist. The all argument controls whether the function should recursively remove all files and sub-directories included as well. If glob is specified, it is called to select files to remove, and the directories are not deleted even if all is true.

val select : ?deep:bool -> ?dft:[ `After | `Before ] -> ?glob:string -> ?filter:(bool -> string -> string -> bool) -> ?follow_links:bool -> ?error:(exn -> string -> string -> unit) -> unit -> string FileSelector.t

select ?deep ?dft ?glob ?filter ?follow_links ?error () creates a selctor to customize a file iterator.

The deep and dft arguments controls whether function should recurse in sub-directories. If deep is true, and ~dft is not specified, the files are listed in breadth-first mode (a,b,a/x,b/x,a/x/y for example). If ~dft is `Before, the files are listed in depth-first mode, and the ancestors are before their children. If ~dft is `After, the are after their children.

The glob argument can be used to filter the basenames of files with a regular expression.

The filter argument is called as filter is_dir basename path where is_dir is set when checking whether to enter or not into a sub-directory, basename is the basename of the file and path is the path starting with a '/', yet relative to the initial directory. filter is called on every file with is_dir false to decide whether it should be added or not, and only on sub-directories with is_dir true to decide whether to enter or not if deep is true.

The follow_links argument is used to decide if a link to directory should be followed (when deep is also set).

The error argument is called when an error occurs, with error exn path filename.

val read_dir : ?select:string FileSelector.t -> string -> string array

read_dir ?select filename returns the files contained in the directory filename.

In a directory, files are sorted in lexicographical order of their names.

val read_dir_to_list : ?select:string FileSelector.t -> string -> string list

Same as read_dir, but returns a list instead of an array

val iter_dir : ?select:string FileSelector.t -> (basename:string -> localpath:string -> file:string -> unit) -> string -> unit

Same as read_dir, but calls a function on every file and directory with the basename, the relative path (yet, starting with a '/') and the filename (i.e. the directory name concatenated with the relative path): f basename path file. It is not equivalent to using read_dir and then itering on the result, as iter_dir the function is called during the traversal, not after.

val iterator : ?select:string FileSelector.t -> string -> unit -> (string * string) option

iterator ?select dir creates an iterator on directory dir. The iterator is a function that returns None when finished, or Some (path, filename) with the next file to iter on.

val mkdir : string -> int -> unit

mkdir filename mode simply creates the directory filename with permissions mode.

val readdir : string -> string array

readdir filename returns the files contained in directory filename as an array of strings. The strings are sorted in lexicographical order.

val rmdir : string -> unit

rmdir filename removes directory filename, or fails if it does not exist or is not a directory.

val cut_at_last_extension : string -> string * string

cut_at_last_extension file returns a pair before_ext,extension, where extension is the last extension, converted to lowercase, and without the initial dot, and before_ext everything before the last dot.

val extensions_of_basename : string -> string list

extensions_of_basename basename returns the list of extensions of the file. The argument must only contain the basename of the file, otherwise the dot may belong to a parent directory.

module String = FileString
module Abstract = FileAbstract
module Channel = FileChannel
OCaml

Innovation. Community. Security.