1Filename(3)                      OCaml library                     Filename(3)
2
3
4

NAME

6       Filename - Operations on file names.
7

Module

9       Module   Filename
10

Documentation

12       Module Filename
13        : sig end
14
15
16       Operations on file names.
17
18
19
20
21
22
23       val current_dir_name : string
24
25       The conventional name for the current directory (e.g.  .  in Unix).
26
27
28
29       val parent_dir_name : string
30
31       The conventional name for the parent of the current directory (e.g.  ..
32       in Unix).
33
34
35
36       val dir_sep : string
37
38       The directory separator (e.g.  / in Unix).
39
40
41       Since 3.11.2
42
43
44
45       val concat : string -> string -> string
46
47
48       concat dir file returns a file name that designates file file in direc‐
49       tory dir .
50
51
52
53       val is_relative : string -> bool
54
55       Return  true  if  the  file  name is relative to the current directory,
56       false if it is absolute (i.e. in Unix, starts with / ).
57
58
59
60       val is_implicit : string -> bool
61
62       Return true if the file name is relative and does not start with an ex‐
63       plicit  reference  to the current directory ( ./ or ../ in Unix), false
64       if it starts with an explicit reference to the root  directory  or  the
65       current directory.
66
67
68
69       val check_suffix : string -> string -> bool
70
71
72       check_suffix  name suff returns true if the filename name ends with the
73       suffix suff .
74
75       Under Windows ports (including Cygwin), comparison is case-insensitive,
76       relying  on String.lowercase_ascii .  Note that this does not match ex‐
77       actly the interpretation of case-insensitive filename equivalence  from
78       Windows.
79
80
81
82       val chop_suffix : string -> string -> string
83
84
85       chop_suffix  name suff removes the suffix suff from the filename name .
86       The behavior is undefined if name does not end with the suffix  suff  .
87       chop_suffix_opt is thus recommended instead.
88
89
90
91       val chop_suffix_opt : suffix:string -> string -> string option
92
93
94       chop_suffix_opt  ~suffix  filename removes the suffix from the filename
95       if possible, or returns None if the filename does not end with the suf‐
96       fix.
97
98       Under Windows ports (including Cygwin), comparison is case-insensitive,
99       relying on String.lowercase_ascii .  Note that this does not match  ex‐
100       actly  the interpretation of case-insensitive filename equivalence from
101       Windows.
102
103
104       Since 4.08
105
106
107
108       val extension : string -> string
109
110
111       extension name is the shortest suffix ext of name0 where:
112
113
114       - name0 is the longest suffix of name that does not contain a directory
115       separator;
116
117       - ext starts with a period;
118
119       - ext is preceded by at least one non-period character in name0 .
120
121       If such a suffix does not exist, extension name is the empty string.
122
123
124       Since 4.04
125
126
127
128       val remove_extension : string -> string
129
130       Return  the  given file name without its extension, as defined in File‐
131       name.extension . If the extension is empty, the  function  returns  the
132       given file name.
133
134       The following invariant holds for any file name s :
135
136
137       remove_extension s ^ extension s = s
138
139
140
141       Since 4.04
142
143
144
145       val chop_extension : string -> string
146
147       Same  as  Filename.remove_extension , but raise Invalid_argument if the
148       given name has an empty extension.
149
150
151
152       val basename : string -> string
153
154       Split a file name into directory name / base file name.  If name  is  a
155       valid  file  name, then concat (dirname name) (basename name) returns a
156       file name which is equivalent to name .  Moreover,  after  setting  the
157       current  directory  to  dirname  name  (with Sys.chdir ), references to
158       basename name (which is a relative file name) designate the  same  file
159       as name before the call to Sys.chdir .
160
161       This  function  conforms  to  the specification of POSIX.1-2008 for the
162       basename utility.
163
164
165
166       val dirname : string -> string
167
168       See Filename.basename .  This function conforms to the specification of
169       POSIX.1-2008 for the dirname utility.
170
171
172
173       val null : string
174
175
176       null is "/dev/null" on POSIX and "NUL" on Windows. It represents a file
177       on the OS that discards all writes and returns end of file on reads.
178
179
180       Since 4.10.0
181
182
183
184       val temp_file : ?temp_dir:string -> string -> string -> string
185
186
187       temp_file prefix suffix returns the name of a fresh temporary  file  in
188       the temporary directory.  The base name of the temporary file is formed
189       by concatenating prefix , then a suitably chosen integer  number,  then
190       suffix .  The optional argument temp_dir indicates the temporary direc‐
191       tory  to   use,   defaulting   to   the   current   result   of   File‐
192       name.get_temp_dir_name  .   The  temporary  file is created empty, with
193       permissions 0o600 (readable and writable only by the file owner).   The
194       file  is  guaranteed  to  be different from any other file that existed
195       when temp_file was called.
196
197
198       Before3.11.2 no ?temp_dir optional argument
199
200
201
202       Raises Sys_error if the file could not be created.
203
204
205
206       val  open_temp_file   :   ?mode:open_flag   list   ->   ?perms:int   ->
207       ?temp_dir:string -> string -> string -> string * out_channel
208
209       Same  as Filename.temp_file , but returns both the name of a fresh tem‐
210       porary file, and an output channel opened (atomically)  on  this  file.
211       This function is more secure than temp_file : there is no risk that the
212       temporary file will be modified (e.g. replaced by a symbolic link)  be‐
213       fore the program opens it.  The optional argument mode is a list of ad‐
214       ditional flags to control the opening of the file.  It can contain  one
215       or  several of Open_append , Open_binary , and Open_text .  The default
216       is [Open_text] (open in text mode). The file is  created  with  permis‐
217       sions  perms (defaults to readable and writable only by the file owner,
218       0o600 ).
219
220
221       Before4.03.0 no ?perms optional argument
222
223
224
225       Before3.11.2 no ?temp_dir optional argument
226
227
228
229       Raises Sys_error if the file could not be opened.
230
231
232
233       val get_temp_dir_name : unit -> string
234
235       The name of the temporary directory: Under Unix, the value of  the  TM‐
236       PDIR environment variable, or "/tmp" if the variable is not set.  Under
237       Windows, the value of the TEMP environment variable,  or  "."   if  the
238       variable is not set.  The temporary directory can be changed with File‐
239       name.set_temp_dir_name .
240
241
242       Since 4.00.0
243
244
245
246       val set_temp_dir_name : string -> unit
247
248       Change the temporary directory returned  by  Filename.get_temp_dir_name
249       and used by Filename.temp_file and Filename.open_temp_file .
250
251
252       Since 4.00.0
253
254
255
256       val temp_dir_name : string
257
258       Deprecated.  You should use Filename.get_temp_dir_name instead.
259
260
261       The  name  of the initial temporary directory: Under Unix, the value of
262       the TMPDIR environment variable, or "/tmp" if the variable is not  set.
263       Under  Windows,  the value of the TEMP environment variable, or "."  if
264       the variable is not set.
265
266
267       Since 3.09.1
268
269
270
271       val quote : string -> string
272
273       Return a quoted version of a file name, suitable for use as  one  argu‐
274       ment  in  a command line, escaping all meta-characters.  Warning: under
275       Windows, the output is only suitable for use with programs that  follow
276       the standard Windows quoting conventions.
277
278
279
280       val  quote_command  :  string  ->  ?stdin:string  ->  ?stdout:string ->
281       ?stderr:string -> string list -> string
282
283
284       quote_command cmd args returns a quoted command line, suitable for  use
285       as an argument to Sys.command , Unix.system , and the Unix.open_process
286       functions.
287
288       The string cmd is the command to call.  The list args is  the  list  of
289       arguments to pass to this command.  It can be empty.
290
291       The  optional  arguments  ?stdin and ?stdout and ?stderr are file names
292       used to redirect the standard input, the standard output, or the  stan‐
293       dard  error of the command.  If ~stdin:f is given, a redirection < f is
294       performed and the standard input of the command reads from file f .  If
295       ~stdout:f  is  given,  a  redirection > f is performed and the standard
296       output of the command is written to file f .  If ~stderr:f is given,  a
297       redirection  2> f is performed and the standard error of the command is
298       written to file f .  If both ~stdout:f and ~stderr:f  are  given,  with
299       the  exact  same  file name f , a 2>&1 redirection is performed so that
300       the standard output and the standard error of the  command  are  inter‐
301       leaved and redirected to the same file f .
302
303       Under Unix and Cygwin, the command, the arguments, and the redirections
304       if any are quoted using  Filename.quote  ,  then  concatenated.   Under
305       Win32, additional quoting is performed as required by the cmd.exe shell
306       that is called by Sys.command .
307
308
309       Since 4.10.0
310
311
312       Raises Failure if the command cannot be escaped on  the  current  plat‐
313       form.
314
315
316
317
318
319OCamldoc                          2022-02-04                       Filename(3)
Impressum