package ez_file

  1. Overview
  2. Docs

Module Ez_file.FileStringSource

File operations with filenames represented by the string type

include FileSig.FILE_OPERATIONS with type t := string
include FileSig.FILENAME_OPERATIONS with type t := string
Sourceval concat : string -> string -> string
Sourceval is_absolute : string -> bool
Sourceval is_relative : string -> bool
Sourceval is_implicit : string -> bool
Sourceval add_suffix : string -> string -> string
Sourceval check_suffix : string -> string -> bool
Sourceval cut_extension : string -> string * string
Sourceval cut_extensions : string -> string * string list
Sourceval basename : string -> string
Sourceval dirname : string -> string
Sourceval add_path : string -> string -> string
Sourceval add_basename : string -> string -> string
Sourceval add_basenames : string -> string list -> string
Sourceval current_dir_name : string
Sourceval open_in : string -> in_channel
Sourceval open_out : string -> out_channel
Sourceval open_in_bin : string -> in_channel
Sourceval open_out_bin : string -> out_channel
Sourceval temp_file : string -> string -> string
Sourceval with_in : string -> (in_channel -> unit) -> unit
Sourceval with_in_bin : string -> (in_channel -> unit) -> unit
Sourceval with_out : string -> (out_channel -> unit) -> unit
Sourceval with_out_bin : string -> (out_channel -> unit) -> unit
Sourceval exists : string -> bool
Sourceval getcwd : unit -> string
Sourceval size : string -> int
Sourceval is_directory : string -> bool
Sourceval remove : string -> unit
Sourceval rename : string -> string -> unit
Sourceval stat : string -> MinUnix.stats
Sourceval lstat : string -> MinUnix.stats
Sourcemodule OP : sig ... end
Sourceval copy_rec : string -> string -> unit
Sourceval uncopy_rec : string -> string -> unit
Sourceval 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
Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval read_sublines_to_list : string -> int -> int -> string list

Same as read_sublines, but returns a list of strings.

Sourceval 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.

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

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

Sourceval 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.

Sourceval 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
Sourcetype selector

Type of the value used to create filters when iterating on files and directories.

Sourceexception NotADirectory of string

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

Sourceval 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.

Sourceval onedir : selector
Sourceval recdir : selector
Sourceval 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 based on their basename, and the directories are not deleted even if all is true.

Sourceval select : ?deep:bool -> ?dft:[ `After | `Before ] -> ?glob:string -> ?path:string -> ?ignore:string -> ?kinds:Unix.file_kind list -> ?filter:(bool -> string -> bool) -> ?follow_links:bool -> ?error:(exn -> string -> unit) -> unit -> selector

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

The deep and dft arguments controls whether function should recurse (false by default) 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, path and ignore arguments can be used to filter the files with regular expressions. glob is used to choose the files to keep based on their basenames, it is not used for the recursion itself. path is used to choose the files to keep based on the path, it is not used for the recursion itself. ignore is used to choose the files to ignore, based on their paths, both during the iteration and the recursion.

The kinds argument can be used to restrict the files to the ones of a particular kind.

The filter argument is used to select the files to keep. filter for_rec path should return true if the file is ok, false otherwise. for_rec is true if filter is called to check a directory for recursion, false if it is called for the iteration.

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 filename. The default behavior is to ignore errors.

Sourceval read_dir : ?select:selector -> string -> string array

read_dir ?select dir returns the files contained in the directory dir, recursively. Filenames start from the root of the given directory, i.e. a full filename would be dir / file.

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

Sourceval read_dir_to_list : ?select:selector -> string -> string list

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

Sourceval iter_dir : ?select:selector -> string -> f:(string -> unit) -> unit

Same as read_dir, but calls a function on every file and directory. 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, so concurrent modifications to the directory might become visible.

Sourceval iterator : ?select:selector -> string -> unit -> string option

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

make_select f transforms f, a function that takes an optional selector, into a function that builds the selector on the fly.

For example: let () = EzFile.make_select EzFile.iter_dir ~deep:true ~f:(fun path -> ...) dirname

which is equivalent to: let () = let select = EzFile.select ~deep:true () in EzFile.iter_dir ~select ~f:(fun path -> ...) dirname

Sourceval make_select : (?select:selector -> string -> 'a) -> ?deep:bool -> ?dft:[ `After | `Before ] -> ?glob:string -> ?path:string -> ?ignore:string -> ?kinds:Unix.file_kind list -> ?filter:(bool -> string -> bool) -> ?follow_links:bool -> ?error:(exn -> string -> unit) -> string -> 'a
Sourceval mkdir : string -> int -> unit

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

Sourceval 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.

Sourceval rmdir : string -> unit

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

OCaml

Innovation. Community. Security.