module Unixutil:Unix utilities.sig
..end
This module provides various helpful utilities for use with the built-in
Unix module.
The stats are included because a lot of people want to check on
the type of file for each file in the list. You can see if you have
a directory by:
This does not necessarily resolve symlinks.
Side-effects: the current working directory is briefly changed, but is changed
back. If
By default, will remove only a given file and will raise an
error if it fails to do so.
if ~force is given and is set true, errors are never raised but simply ignored.
If ~recursive is given and is set true, a directory
name may be given. The directory and all entries beneath it will
be removed.
Author(s): Copyright (C) 2004 John Goerzen
File functions
These functions help process files
val exists :
string -> bool
val isdir :
string -> bool
Directory processing
These functions help process directories.
val list_of_dir :
string -> string list
val fold_directory :
('a -> string -> 'a) -> 'a -> string -> 'a
val recurse_stream :
string -> (string * Unix.stats) Stream.t
will create a stream that yields a (stats, name)
pair for every entry beneath the given filename (including the
filename itself. It's a depth-first traversal.
recurse_stream name
match stats.st_kind with
S_DIR -> ...
| _ -> ...
val recurse_list :
string -> (string * Unix.stats) list
Unixutil.recurse_stream
, but generates a list instead.
Not recommended since this list could be *huge*.
val recurse_cmd :
(string * Unix.stats -> unit) -> string -> unit
will call recurse_cmd func name
on every entry
in or beneath name, which may specify a directory or a file. For entries
in subdirectires, the full relative path starting from name will be
passed.func stats name
val abspath :
string -> string
os.getcwd ()
returns an invalid cwd to start with, results
are undefined and may cause an exception (since it then cannot change back).
This circumstance is rare and probably not of concern to you.
Shell replacements
These functions replace standard shell functions with the same name.
val rm :
?recursive:bool -> ?force:bool -> string -> unit