module FileUtil: sig
.. end
A module to provide the core system utilities to
manipulate file and directory. All function nearly match
common unix utilities ( but try to be more portable )
Types and exceptions
type
filename = string
The base type of the module
exception SizeInvalid
exception FileDoesntExist
exception RecursiveLink of filename
exception RmDirNotEmpty of filename
exception MkdirMissingComponentPath of filename
exception MkdirDirnameAlreadyUsed of filename
exception CpCannotCopy of filename
exception CpNoSourceFile of filename
exception CpCannotCopyFilesToFile of filename list * filename
exception CpCannotCopyDir of filename
exception MvNoSourceFile
type
action_link =
| |
Follow |
| |
Skip |
| |
SkipInform of (filename -> unit) |
| |
AskFollow of (filename -> bool) |
The policy concerning the links which are directory
type
interactive =
For certain command, you should need to ask the user wether
or not he does want to do some action. Provide the function
to Ask or Force the action
type
size =
| |
TB of float |
| |
GB of float |
| |
MB of float |
| |
KB of float |
| |
B of float |
Size type
type
kind =
| |
Dir |
| |
File |
| |
Dev_char |
| |
Dev_block |
| |
Link |
| |
Fifo |
| |
Socket |
Kind of file. This set is a combination of all POSIX file, some of them
doesn't exist at all on certain file system
type
base_permission = {
|
sticky : bool ; |
|
exec : bool ; |
|
write : bool ; |
|
read : bool ; |
}
Base permission. This is the base type for one set of permission
type
permission = {
}
Permission. All the base permission of a file
type
stat = {
|
kind : kind ; |
|
is_link : bool ; |
|
permission : permission ; |
|
size : size ; |
|
owner : int ; |
|
group_owner : int ; |
|
access_time : float ; |
|
modification_time : float ; |
|
creation_time : float ; |
}
Information about a file. This type is derived from Unix.stat
type
test_file =
| |
Is_dev_block |
| |
Is_dev_char |
| |
Is_dir |
| |
Exists |
| |
Is_file |
| |
Is_set_group_ID |
| |
Has_sticky_bit |
| |
Is_link |
| |
Is_pipe |
| |
Is_readable |
| |
Is_writeable |
| |
Size_not_null |
| |
Size_bigger_than of size |
| |
Size_smaller_than of size |
| |
Size_equal_to of size |
| |
Size_fuzzy_equal_to of size |
| |
Is_socket |
| |
Has_set_user_ID |
| |
Is_exec |
| |
Is_owned_by_user_ID |
| |
Is_owned_by_group_ID |
| |
Is_newer_than of filename |
| |
Is_older_than of filename |
| |
Is_newer_than_date of float |
| |
Is_older_than_date of float |
| |
And of test_file * test_file |
| |
Or of test_file * test_file |
| |
Not of test_file |
| |
Match of string |
| |
True |
| |
False |
| |
Has_extension of string |
| |
Has_no_extension |
| |
Is_parent_dir |
| |
Is_current_dir |
| |
Basename_is of filename |
| |
Dirname_is of filename |
| |
Custom of (filename -> bool) |
Pattern you can use to test file
File utils specification
module type OPERATION_REGEXP = sig
.. end
Abstraction of regexp operation
module type FILE_UTILS = sig
.. end
Operation available.
module type META_FILE_UTILS = functor (
OperationRegexp
:
OPERATION_REGEXP
) ->
FILE_UTILS
Meta structure use to define regexp generic file operation
Implementation
Classical permission
val permission_of_int : int -> permission
Understand the POSIX permission integer norm
val int_of_permission : permission -> int
Return the POSIX integer permission associated to the permission
Size operation
val size_convert_down : size -> size
Convert to the upper unit a size
val size_convert_up : size -> size
Convert to the smaller unit a size
val size_compare_unit : size -> size -> int
Compare two units of size : classification of size is
To, Go, Mo, Ko, O
, with To being the bigger unit
val size_to_same_unit : size -> size -> size
size_to_same_unit sz1 sz2 : convert sz2 to the unit of sz1
val size_to_To : size -> size
Convert a size to To
val size_to_Go : size -> size
Convert a size to Go
val size_to_Mo : size -> size
Convert a size to Mo
val size_to_Ko : size -> size
Convert a size to Ko
val size_to_O : size -> size
Convert a size to O
val size_apply_operation : (float -> float -> float) -> size -> size -> size
Apply an operation to a size : the two size are converted
* to the same unit and the function is applied to their value
val size_compare : ?fuzzy:bool -> size -> size -> int
Compare two size, using the classical compare function. The two size
* are converted to the same unit before. If fuzzy is set to true, the
* comparison is done on the floor value of the two size.
val size_add : size -> size -> size
size_add sz1 sz2 : add sz1 to sz2, result is in the unit of sz1
val size_sub : size -> size -> size
size_sub sz1 sz2 : substract sz1 to sz2, result is in the unit of sz1
val string_of_size : ?fuzzy:bool -> size -> string
Convert a value to a string representation. If fuzzy is set to true, only
* consider the most significant unit
module GenericUtil:
Implementation of META_FILE_UTILS
Concrete file utilities
module StrUtil: GenericUtil
(
sig
type
t = Str.regexp
val compile : string -> Str.regexp
val test : Str.regexp -> string -> bool
end
)
Implementation using regexp