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

NAME

6       Stdlib.Filename - no description
7

Module

9       Module   Stdlib.Filename
10

Documentation

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