Frama-C API - Filesystem
File system
val exists : Filepath.t -> bool
Equivalent to Sys.file_exists
.
val is_file : Filepath.t -> bool
is_file f
returns true
iff f
points to a regular file (or a symbolic link pointing to a file). Returns false
if any errors happen when stat
'ing the file.
val is_dir : Filepath.t -> bool
Equivalent to Sys.is_directory
.
val readdir : Filepath.t -> string array
Equivalent to Sys.readdir
.
val list_dir : Filepath.t -> string list
Contents of a directory.
val iter_dir : (string -> unit) -> Filepath.t -> unit
Iter through the contents of a directory.
val fold_dir : (string -> 'a -> 'a) -> Filepath.t -> 'a -> 'a
Fold over the contents of a directory.
val make_dir : ?parents:bool -> Filepath.t -> Unix.file_perm -> bool
make_dir ?parents name perm
creates directory name
with permission perm
. If parents
is true, recursively create parent directories if needed. parents
defaults to false. Note that this function may create some of the parent directories and then fail to create the children, e.g. if perm
does not allow user execution of the created directory. This will leave the filesystem in a modified state before raising an exception. Returns true
if the directory was created, false
otherwise.
val remove_file : Filepath.t -> unit
Tries to delete a file and never fails.
val remove_dir : Filepath.t -> unit
Tries to delete a directory and never fails.
val rename : Filepath.t -> Filepath.t -> unit
Equivalent to Sys.rename
.
Temporary files
See Temp_files
module for automatic removal of temp files at exit.
val temp_file : prefix:string -> suffix:string -> Filepath.t
Similar to Filename.temp_file
.
val temp_dir : prefix:string -> suffix:string -> Filepath.t
Similar to Filename.temp_dir
.
File comparison
val digest : Filepath.t -> string
digest p
computes the hash of a file p
using Stdlib.Digest.file
.
val same_digest : Filepath.t -> Filepath.t -> bool
same_digest p1 p2
compares the hashes of two files p1
and p2
using Stdlib.Digest.file
and returns true
if they have the same.
High level Input/Output
val copy_file : Filepath.t -> Filepath.t -> unit
copy_file source target
copies source file to target file.
val iter_lines : Filepath.t -> (string -> unit) -> unit
Iter over all text lines in the file
Low level file Input/Output
This type defines what action with_open_in
and with_open_out
must perform when the file to open does not exist.
This type define what action with_open_out
must perform when the file to open already exists.
A safe_processor
helps to handle file operations while ensuring the file will be closed no matter what happens. It is a function that takes a file operation f
as a parameter, opens a file and calls the f
with the newly-created channel.
Same as safe_processor
but when a Sys_error
is raised, re-raise it after closing the file
val with_open_in : ?if_missing:action_if_missing -> ?binary:bool -> ?blocking:bool -> Filepath.t -> (Stdlib.in_channel, 'a) safe_processor
with_open_in path f
opens file path
for reading and calls f
with the newly-created input channel. The file is closed when f
returns or whenever an exception is thrown by f
.
val with_open_in_exn : ?if_missing:action_if_missing -> ?binary:bool -> ?blocking:bool -> Filepath.t -> (Stdlib.in_channel, 'a) exn_processor
Same as with_open_in
but raises Sys_error
instead of returning Error
.
val with_open_out : ?if_missing:action_if_missing -> ?if_exists:action_if_exists -> ?binary:bool -> ?blocking:bool -> Filepath.t -> (Stdlib.out_channel, 'a) safe_processor
with_open_out path f
calls f
with a new output channel on the file path
opened for writing. The file is closed when f
returns or whenever an exception is thrown by f
.
val with_open_out_exn : ?if_missing:action_if_missing -> ?if_exists:action_if_exists -> ?binary:bool -> ?blocking:bool -> Filepath.t -> (Stdlib.out_channel, 'a) exn_processor
Same as with_open_out
but raises Sys_error
instead of returning Error
.
val with_formatter : Filepath.t -> (Stdlib.Format.formatter, 'a) safe_processor
with_formatter path f
calls f
with a formatter writing to the file path
. The file is closed and the formatter is flushed when f
returns or whenever an exception is thrown by f
.
val with_formatter_exn : Filepath.t -> (Stdlib.Format.formatter, 'a) exn_processor
Same as with_formatter
but raises Sys_error
instead of returning Error
.
module Compressed : sig ... end
module Operators : sig ... end
Opening this module allows to use shorter syntax to deal with files.