File: filepath.mli

package info (click to toggle)
ocaml-obuild 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,456 kB
  • sloc: ml: 14,491; sh: 211; ansic: 34; makefile: 11
file content (69 lines) | stat: -rw-r--r-- 2,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(** The module [Filepath] defines two types, [filepath] and [filename] to represent paths and file
    names in a file system.

    * a [filepath] represent a path in a filesystem. It can be relative or absolute, and is composed
    of components. The last component can correspond to a directory or a file in a filesystem. Other
    components correspond to directories.

    * a [filename] encapsulate the name of a file. *)

(** Exceptions *)

exception EmptyFilename
(** [EmptyFilename] is raised by [fn] when trying to create a value of type [filename] out of
    strings "", "." or ".." *)

exception InvalidFilename of string
(** [InvalidFilename fn] is raised by [fn] when trying to create a value of type [filename] when
    [fn] contains [Filename.dir_sep]. *)

(** Types *)

type filepath
(** Type representing a path in a filesystem. *)

type filename
(** Type representing a file in a filesystem. *)

val empty_fn : filename
(** Filename guaranteed to point to no valid file. Useful for initializing structures that have a
    field of type [filename]. *)

val current_dir : filepath
(** Filepath pointing to the current working directory. *)

(** Functions to convert the above types to and from string. *)

val fp_to_string : filepath -> string
val fn_to_string : filename -> string
val fp : string -> filepath
val fn : string -> filename
val is_absolute : filepath -> bool

val valid_fn : string -> bool
(** [valid_fn s] returns [true] if [s] is a valid file name, i.e. not ".", "..", not containing
    [Filename.dir_sep]. *)

val ( <//> ) : filepath -> filepath -> filepath
(** [fp1 <//> fp2] concatenate [fp2] to [fp1]. [fp2] cannot be an absolute path. *)

val ( </> ) : filepath -> filename -> filepath
(** [fp </> fn] concatenate [fn] to [fp]. *)

val ( <.> ) : filename -> string -> filename
(** [fn <.> ext] appends the extension [ext] to [fn]. *)

val in_current_dir : filename -> filepath
(** [in_current_dir fn] is equivalent to [current_dir </> fn]. *)

val path_length : filepath -> int
(** [path_length fp] returns the number of components in [fp], including the last (basename) one. *)

val path_dirname : filepath -> filepath
(** Analogous to [Filename.dirname], but operate on [filepath]s. *)

val path_basename : filepath -> filename
(** Analogous to [Filename.basename], but operate on [filepath]s. *)

val chop_extension : filename -> filename
(** Analogous to [Filename.chop_extension], but for [filename]s. *)