module IO: CCIO
type'a
or_error =('a, string) Result.result
type'a
gen =unit -> 'a option
Gen
in the gen libraryval with_in : ?mode:int ->
?flags:Pervasives.open_flag list ->
string -> (Pervasives.in_channel -> 'a) -> 'a
Sys_error
in case of error (same as open_in
and close_in
)flags
: opening flags (default [Open_text]
). Open_rdonly
is used in any casesval read_chunks : ?size:int -> Pervasives.in_channel -> string gen
size
val read_line : Pervasives.in_channel -> string option
None
if the input is terminated.
The "\n" is removed from the line.val read_lines : Pervasives.in_channel -> string gen
val read_lines_l : Pervasives.in_channel -> string list
val read_all : ?size:int -> Pervasives.in_channel -> string
size
: the internal buffer sizeval read_all_bytes : ?size:int -> Pervasives.in_channel -> Bytes.t
size
: the internal buffer sizeval with_out : ?mode:int ->
?flags:Pervasives.open_flag list ->
string -> (Pervasives.out_channel -> 'a) -> 'a
CCIO.with_in
but for an output channelSys_error
in case of error (same as open_out
and close_out
)
Open_wronly
is used in any casesflags
: opening flags (default [Open_creat; Open_trunc; Open_text]
).val with_out_a : ?mode:int ->
?flags:Pervasives.open_flag list ->
string -> (Pervasives.out_channel -> 'a) -> 'a
CCIO.with_out
but with the [Open_append; Open_creat; Open_wronly]
flags activated, to append to the file.Sys_error
in case of error (same as open_out
and close_out
)val write_line : Pervasives.out_channel -> string -> unit
val write_gen : ?sep:string -> Pervasives.out_channel -> string gen -> unit
sep
between
every two strings (but not at the end)val write_lines : Pervasives.out_channel -> string gen -> unit
val write_lines_l : Pervasives.out_channel -> string list -> unit
val with_in_out : ?mode:int ->
?flags:Pervasives.open_flag list ->
string -> (Pervasives.in_channel -> Pervasives.out_channel -> 'a) -> 'a
flags
: opening flags (default [Open_creat]
)val tee : ('a -> unit) list -> 'a gen -> 'a gen
tee funs gen
behaves like gen
, but each element is given to
every function f
in funs
at the time the element is produced.How to list recursively files in a directory:
# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
# CCIO.write_lines stdout files;;
See CCIO.File.walk
if you also need to list directories:
# let content = CCIO.File.walk (CCIO.File.make "/tmp");;
# Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;;
module File:sig
..end