Page
Library
Module
Module type
Parameter
Class
Class type
Source
FileUtilSourcePOSIX utilities for files and directories.
A module to provide the core POSIX utilities to manipulate files and directories. All functions try to mimic common POSIX utilities but are written in pure OCaml.
exception FileDoesntExist of FilePath.filenameexception RecursiveLink of FilePath.filenameGeneric error handling functions. Whenever such a function is available it helps report the error and allows to raise an exception. The string provided is the human readable version of 'a. In most cases 'a is a polymorphic variant.
Exception raised when after an error_handler the execution cannot continue. The rest of the workflow logic cannot handle the default case and the whole operation can be in the middle of transformation.
type action_link = | FollowWe consider link as simple directory (it is dangerous)
*)| SkipJust skip it
*)| SkipInform of FilePath.filename -> unitSkip and execute an action
*)| AskFollow of FilePath.filename -> boolAsk and wait for input, false means skip
*)Policy concerning links which are directories.
For certain command, you should need to ask the user wether or not he wants to act.
Base permission. This is the permission corresponding to one user or group.
Full permission. All the base permissions of a file.
val permission_of_int : int -> permissionTranslate POSIX integer permission.
val int_of_permission : permission -> intReturn the POSIX integer permission
val byte_of_size : size -> int64Convert size to bytes.
Compare two sizes, using the classical compare function. If fuzzy is set to true, the comparison is done on the most significant size unit of both value.
val string_of_size : ?fuzzy:bool -> size -> stringConvert a value to a string representation. If fuzzy is set to true, only consider the most significant unit
Kind of file. This set is a combination of all POSIX file, some of them doesn't exist at all on certain file system or OS.
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;device : int;inode : int;}Information about a file. This type is derived from Unix.stat
val stat : ?dereference:bool -> FilePath.filename -> statstat fln Return information about the file (like Unix.stat) Non POSIX command.
val umask :
?error:umask_error error_handler ->
?mode:[< `Octal of int | `Symbolic of Mode.t ] ->
[< `Octal of int -> 'a | `Symbolic of Mode.t -> 'a ] ->
'aGet or set the file mode creation mask. See POSIX documentation.
type test_file = | Is_dev_blockFILE is block special
*)| Is_dev_charFILE is character special
*)| Is_dirFILE is a directory
*)| ExistsFILE exists
*)| Is_fileFILE is a regular file
*)| Is_set_group_IDFILE is set-group-ID
*)| Has_sticky_bitFILE has its sticky bit set
*)| Is_linkFILE is a symbolic link
*)| Is_pipeFILE is a named pipe
*)| Is_readableFILE is readable
*)| Is_writeableFILE is writeable
*)| Size_not_nullFILE has a size greater than zero
*)| Size_bigger_than of sizeFILE has a size greater than given size
*)| Size_smaller_than of sizeFILE has a size smaller than given size
*)| Size_equal_to of sizeFILE has the same size as given size
*)| Size_fuzzy_equal_to of sizeFILE has approximatively the same size as given size
*)| Is_socketFILE is a socket
*)| Has_set_user_IDFILE its set-user-ID bit is set
*)| Is_execFILE is executable
*)| Is_owned_by_user_IDFILE is owned by the effective user ID
*)| Is_owned_by_group_IDFILE is owned by the effective group ID
*)| Is_newer_than of FilePath.filenameFILE1 is newer (modification date) than FILE2
*)| Is_older_than of FilePath.filenameFILE1 is older than FILE2
*)| Is_newer_than_date of floatFILE is newer than given date
*)| Is_older_than_date of floatFILE is older than given date
*)| And of test_file * test_fileResult of TEST1 and TEST2
*)| Or of test_file * test_fileResult of TEST1 or TEST2
*)| Not of test_fileResult of not TEST
*)| Match of stringCompilable match (Str or PCRE or ...)
*)| TrueAlways true
*)| FalseAlways false
*)| Has_extension of FilePath.extensionCheck extension
*)| Has_no_extensionCheck absence of extension
*)| Is_parent_dirBasename is the parent dir
*)| Is_current_dirBasename is the current dir
*)| Basename_is of FilePath.filenameCheck the basename
*)| Dirname_is of FilePath.filenameCheck the dirname
*)| Custom of FilePath.filename -> boolCustom operation on filename
*)Pattern you can use to test file. If the file doesn't exist the result is always false.
val test :
?match_compile:(FilePath.filename -> FilePath.filename -> bool) ->
test_file ->
FilePath.filename ->
boolTest a file. See POSIX documentation.
val chmod :
?error:chmod_error error_handler ->
?recurse:bool ->
[< `Octal of Unix.file_perm | `Symbolic of Mode.t ] ->
FilePath.filename list ->
unitChange permissions of files. See POSIX documentation.
type mkdir_error = [ | `DirnameAlreadyUsed of FilePath.filename| `Exc of exn| `MissingComponentPath of FilePath.filename| `MkdirChmod of FilePath.filename * Unix.file_perm * string * chmod_error ]Possible mkdir errors.
val mkdir :
?error:mkdir_error error_handler ->
?parent:bool ->
?mode:[< `Octal of Unix.file_perm | `Symbolic of Mode.t ] ->
FilePath.filename ->
unitCreate the directory which name is provided. Set ~parent to true if you also want to create every directory of the path. Use mode to provide some specific right. See POSIX documentation.
type rm_error = [ | `DirNotEmpty of FilePath.filename| `Exc of exn| `NoRecurse of FilePath.filename ]Possible rm errors.
val rm :
?error:rm_error error_handler ->
?force:interactive ->
?recurse:bool ->
FilePath.filename list ->
unitRemove the filename provided. Set ~recurse to true in order to completely delete a directory. See POSIX documentation.
type cp_error = [ | `CannotChmodDstDir of FilePath.filename * exn| `CannotCopyDir of FilePath.filename| `CannotCopyFilesToFile of FilePath.filename list * FilePath.filename| `CannotCreateDir of FilePath.filename * exn| `CannotListSrcDir of FilePath.filename * exn| `CannotOpenDstFile of FilePath.filename * exn| `CannotOpenSrcFile of FilePath.filename * exn| `CannotRemoveDstFile of FilePath.filename * exn| `DstDirNotDir of FilePath.filename| `ErrorRead of FilePath.filename * exn| `ErrorWrite of FilePath.filename * exn| `Exc of exn| `NoSourceFile of FilePath.filename| `PartialWrite of FilePath.filename * int * int| `SameFile of FilePath.filename * FilePath.filename| `UnhandledType of FilePath.filename * kind ]Possible cp errors.
val cp :
?follow:action_link ->
?force:interactive ->
?recurse:bool ->
?preserve:bool ->
?error:cp_error error_handler ->
FilePath.filename list ->
FilePath.filename ->
unitCopy the hierarchy of files/directory to another destination. See POSIX documentation.
type mv_error = [ | `Exc of exn| `MvCp of FilePath.filename * FilePath.filename * string * cp_error| `MvRm of FilePath.filename * string * rm_error| `NoSourceFile ]Possible mv errors.
val mv :
?error:mv_error error_handler ->
?force:interactive ->
FilePath.filename ->
FilePath.filename ->
unitMove files/directories to another destination. See POSIX documentation.
type touch_time_t = | Touch_nowUse Unix.gettimeofday
*)| Touch_file_time of FilePath.filenameGet mtime of file
*)| Touch_timestamp of floatUse GMT timestamp
*)Time for file
val touch :
?atime:bool ->
?mtime:bool ->
?create:bool ->
?time:touch_time_t ->
FilePath.filename ->
unitModify the timestamp of the given filename. See POSIX documentation. If atime and mtime are not specified, they are both considered true. If only atime or mtime is sepcified, the other is false.
val filter : test_file -> FilePath.filename list -> FilePath.filename listApply a filtering pattern to a filename.
val ls : FilePath.filename -> FilePath.filename listList the content of a directory. See POSIX documentation.
val pwd : unit -> FilePath.filenameReturn the current dir. See POSIX documentation.
val readlink : FilePath.filename -> FilePath.filenameResolve to the real filename removing symlink. Non POSIX command.
val which :
?path:FilePath.filename list ->
FilePath.filename ->
FilePath.filenameTry to find the executable in the PATH. Use environement variable PATH if none is provided. Non POSIX command.
val cmp :
?skip1:int ->
FilePath.filename ->
?skip2:int ->
FilePath.filename ->
int optioncmp skip1 fln1 skip2 fln2 Compare files fln1 and fln2 starting at pos skip1 skip2 and returning the first octect where a difference occurs. Returns Some -1 if one of the files is not readable or if it is not a file. Returns None if given two identical files. See POSIX documentation.
val du : FilePath.filename list -> size * (FilePath.filename * size) listdu fln_lst Return the amount of space of all the file which are subdir of fln_lst. Also return details for each file scanned. See POSIX documentation.
val find :
?follow:action_link ->
?match_compile:(FilePath.filename -> FilePath.filename -> bool) ->
test_file ->
FilePath.filename ->
('a -> FilePath.filename -> 'a) ->
'a ->
'afind ~follow:fol tst fln exec accu Descend the directory tree starting from the given filename and using the test provided. You cannot match current_dir and parent_dir. For every file found, the action exec is done, using the accu to start. For a simple file listing, you can use find True "." (fun x y -> y :: x) [] See POSIX documentation.
For future release:
val pathchk: filename -> boolean * string, check whether file names are valid or portableval setfacl: filename -> permission -> unit, set file access control lists (UNIX + extended attribute)val getfacl: filename -> permission, get file access control listsACL related function will be handled through a plugin system to handle at runtime which attribute can be read/write (i.e. Win32 ACL, NFS acl, Linux ACL -- or none).