man-pages/man3/Filename.3o.html
2021-03-31 01:06:50 +01:00

628 lines
8.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Filename</TITLE>
</HEAD><BODY>
<H1>Filename</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Filename - Operations on file names.
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Filename
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Filename</B>
<BR>&nbsp;:&nbsp;
<B>sig end</B>
<P>
<P>
Operations on file names.
<P>
<P>
<P>
<P>
<P>
<P>
<I>val current_dir_name </I>
:
<B>string</B>
<P>
The conventional name for the current directory (e.g.
<B>.</B>
in Unix).
<P>
<P>
<P>
<I>val parent_dir_name </I>
:
<B>string</B>
<P>
The conventional name for the parent of the current directory
(e.g.
<B>..</B>
in Unix).
<P>
<P>
<P>
<I>val dir_sep </I>
:
<B>string</B>
<P>
The directory separator (e.g.
<B>/</B>
in Unix).
<P>
<P>
<B>Since</B>
3.11.2
<P>
<P>
<P>
<I>val concat </I>
:
<B>string -&gt; string -&gt; string</B>
<P>
<P>
<B>concat dir file</B>
returns a file name that designates file
<B>file</B>
in directory
<B>dir</B>
.
<P>
<P>
<P>
<I>val is_relative </I>
:
<B>string -&gt; bool</B>
<P>
Return
<B>true</B>
if the file name is relative to the current
directory,
<B>false</B>
if it is absolute (i.e. in Unix, starts
with
<B>/</B>
).
<P>
<P>
<P>
<I>val is_implicit </I>
:
<B>string -&gt; bool</B>
<P>
Return
<B>true</B>
if the file name is relative and does not start
with an explicit reference to the current directory (
<B>./</B>
or
<B>../</B>
in Unix),
<B>false</B>
if it starts with an explicit reference
to the root directory or the current directory.
<P>
<P>
<P>
<I>val check_suffix </I>
:
<B>string -&gt; string -&gt; bool</B>
<P>
<P>
<B>check_suffix name suff</B>
returns
<B>true</B>
if the filename
<B>name</B>
ends with the suffix
<B>suff</B>
.
<P>
Under Windows ports (including Cygwin), comparison is
case-insensitive, relying on
<B>String.lowercase_ascii</B>
. Note that
this does not match exactly the interpretation of case-insensitive
filename equivalence from Windows.
<P>
<P>
<P>
<I>val chop_suffix </I>
:
<B>string -&gt; string -&gt; string</B>
<P>
<P>
<B>chop_suffix name suff</B>
removes the suffix
<B>suff</B>
from
the filename
<B>name</B>
. The behavior is undefined if
<B>name</B>
does not
end with the suffix
<B>suff</B>
.
<B>chop_suffix_opt</B>
is thus recommended
instead.
<P>
<P>
<P>
<I>val chop_suffix_opt </I>
:
<B>suffix:string -&gt; string -&gt; string option</B>
<P>
<P>
<B>chop_suffix_opt ~suffix filename</B>
removes the suffix from
the
<B>filename</B>
if possible, or returns
<B>None</B>
if the
filename does not end with the suffix.
<P>
Under Windows ports (including Cygwin), comparison is
case-insensitive, relying on
<B>String.lowercase_ascii</B>
. Note that
this does not match exactly the interpretation of case-insensitive
filename equivalence from Windows.
<P>
<P>
<B>Since</B>
4.08
<P>
<P>
<P>
<I>val extension </I>
:
<B>string -&gt; string</B>
<P>
<P>
<B>extension name</B>
is the shortest suffix
<B>ext</B>
of
<B>name0</B>
where:
<P>
<P>
-
<B>name0</B>
is the longest suffix of
<B>name</B>
that does not
contain a directory separator;
<P>
-
<B>ext</B>
starts with a period;
<P>
-
<B>ext</B>
is preceded by at least one non-period character
in
<B>name0</B>
.
<P>
If such a suffix does not exist,
<B>extension name</B>
is the empty
string.
<P>
<P>
<B>Since</B>
4.04
<P>
<P>
<P>
<I>val remove_extension </I>
:
<B>string -&gt; string</B>
<P>
Return the given file name without its extension, as defined
in
<B>Filename.extension</B>
. If the extension is empty, the function
returns the given file name.
<P>
The following invariant holds for any file name
<B>s</B>
:
<P>
<P>
<B>remove_extension s ^ extension s = s</B>
<P>
<P>
<P>
<B>Since</B>
4.04
<P>
<P>
<P>
<I>val chop_extension </I>
:
<B>string -&gt; string</B>
<P>
Same as
<B>Filename.remove_extension</B>
, but raise
<B>Invalid_argument</B>
if the given name has an empty extension.
<P>
<P>
<P>
<I>val basename </I>
:
<B>string -&gt; string</B>
<P>
Split a file name into directory name / base file name.
If
<B>name</B>
is a valid file name, then
<B>concat (dirname name) (basename name)</B>
returns a file name which is equivalent to
<B>name</B>
. Moreover,
after setting the current directory to
<B>dirname name</B>
(with
<B>Sys.chdir</B>
),
references to
<B>basename name</B>
(which is a relative file name)
designate the same file as
<B>name</B>
before the call to
<B>Sys.chdir</B>
.
<P>
This function conforms to the specification of POSIX.1-2008 for the
<B>basename</B>
utility.
<P>
<P>
<P>
<I>val dirname </I>
:
<B>string -&gt; string</B>
<P>
See
<B>Filename.basename</B>
.
This function conforms to the specification of POSIX.1-2008 for the
<B>dirname</B>
utility.
<P>
<P>
<P>
<I>val temp_file </I>
:
<B>?temp_dir:string -&gt; string -&gt; string -&gt; string</B>
<P>
<P>
<B>temp_file prefix suffix</B>
returns the name of a
fresh temporary file in the temporary directory.
The base name of the temporary file is formed by concatenating
<B>prefix</B>
, then a suitably chosen integer number, then
<B>suffix</B>
.
The optional argument
<B>temp_dir</B>
indicates the temporary directory
to use, defaulting to the current result of
<B>Filename.get_temp_dir_name</B>
.
The temporary file is created empty, with permissions
<B>0o600</B>
(readable and writable only by the file owner). The file is
guaranteed to be different from any other file that existed when
<B>temp_file</B>
was called.
Raise
<B>Sys_error</B>
if the file could not be created.
<P>
<P>
<B>Before3.11.2</B>
no ?temp_dir optional argument
<P>
<P>
<P>
<P>
<I>val open_temp_file </I>
:
<B>?mode:open_flag list -&gt;</B>
<B>?perms:int -&gt;</B>
<B>?temp_dir:string -&gt; string -&gt; string -&gt; string * out_channel</B>
<P>
Same as
<B>Filename.temp_file</B>
, but returns both the name of a fresh
temporary file, and an output channel opened (atomically) on
this file. This function is more secure than
<B>temp_file</B>
: there
is no risk that the temporary file will be modified (e.g. replaced
by a symbolic link) before the program opens it. The optional argument
<B>mode</B>
is a list of additional flags to control the opening of the file.
It can contain one or several of
<B>Open_append</B>
,
<B>Open_binary</B>
,
and
<B>Open_text</B>
. The default is
<B>[Open_text]</B>
(open in text mode). The
file is created with permissions
<B>perms</B>
(defaults to readable and
writable only by the file owner,
<B>0o600</B>
).
<P>
<P>
<B>Before4.03.0</B>
no ?perms optional argument
<P>
<P>
<P>
<B>Before3.11.2</B>
no ?temp_dir optional argument
<P>
<P>
<P>
<B>Raises Sys_error</B>
if the file could not be opened.
<P>
<P>
<P>
<I>val get_temp_dir_name </I>
:
<B>unit -&gt; string</B>
<P>
The name of the temporary directory:
Under Unix, the value of the
<B>TMPDIR</B>
environment variable, or &quot;/tmp&quot;
if the variable is not set.
Under Windows, the value of the
<B>TEMP</B>
environment variable, or &quot;.&quot;
if the variable is not set.
The temporary directory can be changed with
<B>Filename.set_temp_dir_name</B>
.
<P>
<P>
<B>Since</B>
4.00.0
<P>
<P>
<P>
<I>val set_temp_dir_name </I>
:
<B>string -&gt; unit</B>
<P>
Change the temporary directory returned by
<B>Filename.get_temp_dir_name</B>
and used by
<B>Filename.temp_file</B>
and
<B>Filename.open_temp_file</B>
.
<P>
<P>
<B>Since</B>
4.00.0
<P>
<P>
<P>
<I>val temp_dir_name </I>
:
<B>string</B>
<P>
<B>Deprecated.</B>
You should use
<B>Filename.get_temp_dir_name</B>
instead.
<P>
<P>
The name of the initial temporary directory:
Under Unix, the value of the
<B>TMPDIR</B>
environment variable, or &quot;/tmp&quot;
if the variable is not set.
Under Windows, the value of the
<B>TEMP</B>
environment variable, or &quot;.&quot;
if the variable is not set.
<P>
<P>
<B>Since</B>
3.09.1
<P>
<P>
<P>
<I>val quote </I>
:
<B>string -&gt; string</B>
<P>
Return a quoted version of a file name, suitable for use as
one argument in a command line, escaping all meta-characters.
Warning: under Windows, the output is only suitable for use
with programs that follow the standard Windows quoting
conventions.
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:43 GMT, March 31, 2021
</BODY>
</HTML>