mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-17 08:06:43 -05:00
14 lines
No EOL
17 KiB
HTML
14 lines
No EOL
17 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Filename (ocaml.Stdlib.Filename)</title><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> – <a href="../../index.html">ocaml</a> » <a href="../index.html">Stdlib</a> » Filename</nav><header class="odoc-preamble"><h1>Module <code><span>Stdlib.Filename</span></code></h1><p>Operations on file names.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec value anchored" id="val-current_dir_name"><a href="#val-current_dir_name" class="anchor"></a><code><span><span class="keyword">val</span> current_dir_name : string</span></code></div><div class="spec-doc"><p>The conventional name for the current directory (e.g. <code>.</code> in Unix).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-parent_dir_name"><a href="#val-parent_dir_name" class="anchor"></a><code><span><span class="keyword">val</span> parent_dir_name : string</span></code></div><div class="spec-doc"><p>The conventional name for the parent of the current directory (e.g. <code>..</code> in Unix).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-dir_sep"><a href="#val-dir_sep" class="anchor"></a><code><span><span class="keyword">val</span> dir_sep : string</span></code></div><div class="spec-doc"><p>The directory separator (e.g. <code>/</code> in Unix).</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.11.2</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-concat"><a href="#val-concat" class="anchor"></a><code><span><span class="keyword">val</span> concat : <span>string <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p><code>concat dir file</code> returns a file name that designates file <code>file</code> in directory <code>dir</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_relative"><a href="#val-is_relative" class="anchor"></a><code><span><span class="keyword">val</span> is_relative : <span>string <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p>Return <code>true</code> if the file name is relative to the current directory, <code>false</code> if it is absolute (i.e. in Unix, starts with <code>/</code>).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_implicit"><a href="#val-is_implicit" class="anchor"></a><code><span><span class="keyword">val</span> is_implicit : <span>string <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p>Return <code>true</code> if the file name is relative and does not start with an explicit reference to the current directory (<code>./</code> or <code>../</code> in Unix), <code>false</code> if it starts with an explicit reference to the root directory or the current directory.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check_suffix"><a href="#val-check_suffix" class="anchor"></a><code><span><span class="keyword">val</span> check_suffix : <span>string <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>check_suffix name suff</code> returns <code>true</code> if the filename <code>name</code> ends with the suffix <code>suff</code>.</p><p>Under Windows ports (including Cygwin), comparison is case-insensitive, relying on <code>String.lowercase_ascii</code>. Note that this does not match exactly the interpretation of case-insensitive filename equivalence from Windows.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-chop_suffix"><a href="#val-chop_suffix" class="anchor"></a><code><span><span class="keyword">val</span> chop_suffix : <span>string <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p><code>chop_suffix name suff</code> removes the suffix <code>suff</code> from the filename <code>name</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Invalid_argument</span> <p>if <code>name</code> does not end with the suffix <code>suff</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-chop_suffix_opt"><a href="#val-chop_suffix_opt" class="anchor"></a><code><span><span class="keyword">val</span> chop_suffix_opt : <span>suffix:string <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> <span>string option</span></span></code></div><div class="spec-doc"><p><code>chop_suffix_opt ~suffix filename</code> removes the suffix from the <code>filename</code> if possible, or returns <code>None</code> if the filename does not end with the suffix.</p><p>Under Windows ports (including Cygwin), comparison is case-insensitive, relying on <code>String.lowercase_ascii</code>. Note that this does not match exactly the interpretation of case-insensitive filename equivalence from Windows.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.08</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-extension"><a href="#val-extension" class="anchor"></a><code><span><span class="keyword">val</span> extension : <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p><code>extension name</code> is the shortest suffix <code>ext</code> of <code>name0</code> where:</p><ul><li><code>name0</code> is the longest suffix of <code>name</code> that does not contain a directory separator;</li><li><code>ext</code> starts with a period;</li><li><code>ext</code> is preceded by at least one non-period character in <code>name0</code>.</li></ul><p>If such a suffix does not exist, <code>extension name</code> is the empty string.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.04</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-remove_extension"><a href="#val-remove_extension" class="anchor"></a><code><span><span class="keyword">val</span> remove_extension : <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p>Return the given file name without its extension, as defined in <a href="#val-extension"><code>Filename.extension</code></a>. If the extension is empty, the function returns the given file name.</p><p>The following invariant holds for any file name <code>s</code>:</p><p><code>remove_extension s ^ extension s = s</code></p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.04</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-chop_extension"><a href="#val-chop_extension" class="anchor"></a><code><span><span class="keyword">val</span> chop_extension : <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p>Same as <a href="#val-remove_extension"><code>Filename.remove_extension</code></a>, but raise <code>Invalid_argument</code> if the given name has an empty extension.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-basename"><a href="#val-basename" class="anchor"></a><code><span><span class="keyword">val</span> basename : <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p>Split a file name into directory name / base file name. If <code>name</code> is a valid file name, then <code>concat (dirname name) (basename name)</code> returns a file name which is equivalent to <code>name</code>. Moreover, after setting the current directory to <code>dirname name</code> (with <a href="../Sys/index.html#val-chdir"><code>Sys.chdir</code></a>), references to <code>basename name</code> (which is a relative file name) designate the same file as <code>name</code> before the call to <a href="../Sys/index.html#val-chdir"><code>Sys.chdir</code></a>.</p><p>This function conforms to the specification of POSIX.1-2008 for the <code>basename</code> utility.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-dirname"><a href="#val-dirname" class="anchor"></a><code><span><span class="keyword">val</span> dirname : <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p>See <a href="#val-basename"><code>Filename.basename</code></a>. This function conforms to the specification of POSIX.1-2008 for the <code>dirname</code> utility.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-null"><a href="#val-null" class="anchor"></a><code><span><span class="keyword">val</span> null : string</span></code></div><div class="spec-doc"><p><code>null</code> is <code>"/dev/null"</code> on POSIX and <code>"NUL"</code> on Windows. It represents a file on the OS that discards all writes and returns end of file on reads.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.10.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-temp_file"><a href="#val-temp_file" class="anchor"></a><code><span><span class="keyword">val</span> temp_file : <span>?temp_dir:string <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p><code>temp_file prefix suffix</code> returns the name of a fresh temporary file in the temporary directory. The base name of the temporary file is formed by concatenating <code>prefix</code>, then a suitably chosen integer number, then <code>suffix</code>. The optional argument <code>temp_dir</code> indicates the temporary directory to use, defaulting to the current result of <a href="#val-get_temp_dir_name"><code>Filename.get_temp_dir_name</code></a>. The temporary file is created empty, with permissions <code>0o600</code> (readable and writable only by the file owner). The file is guaranteed to be different from any other file that existed when <code>temp_file</code> was called.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Sys_error</span> <p>if the file could not be created.</p></li></ul><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">3.11.2</span> <p>no ?temp_dir optional argument</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-open_temp_file"><a href="#val-open_temp_file" class="anchor"></a><code><span><span class="keyword">val</span> open_temp_file :
|
||
<span>?mode:<span><a href="../index.html#type-open_flag">open_flag</a> list</span> <span class="arrow">-></span></span>
|
||
<span>?perms:int <span class="arrow">-></span></span>
|
||
<span>?temp_dir:string <span class="arrow">-></span></span>
|
||
<span>string <span class="arrow">-></span></span>
|
||
<span>string <span class="arrow">-></span></span>
|
||
string * <a href="../index.html#type-out_channel">out_channel</a></span></code></div><div class="spec-doc"><p>Same as <a href="#val-temp_file"><code>Filename.temp_file</code></a>, 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 <code>temp_file</code>: 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 <code>mode</code> is a list of additional flags to control the opening of the file. It can contain one or several of <code>Open_append</code>, <code>Open_binary</code>, and <code>Open_text</code>. The default is <code>[Open_text]</code> (open in text mode). The file is created with permissions <code>perms</code> (defaults to readable and writable only by the file owner, <code>0o600</code>).</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Sys_error</span> <p>if the file could not be opened.</p></li></ul><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">4.03.0</span> <p>no ?perms optional argument</p></li></ul><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">3.11.2</span> <p>no ?temp_dir optional argument</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_temp_dir_name"><a href="#val-get_temp_dir_name" class="anchor"></a><code><span><span class="keyword">val</span> get_temp_dir_name : <span>unit <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p>The name of the temporary directory: Under Unix, the value of the <code>TMPDIR</code> environment variable, or "/tmp" if the variable is not set. Under Windows, the value of the <code>TEMP</code> environment variable, or "." if the variable is not set. The temporary directory can be changed with <a href="#val-set_temp_dir_name"><code>Filename.set_temp_dir_name</code></a>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_temp_dir_name"><a href="#val-set_temp_dir_name" class="anchor"></a><code><span><span class="keyword">val</span> set_temp_dir_name : <span>string <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Change the temporary directory returned by <a href="#val-get_temp_dir_name"><code>Filename.get_temp_dir_name</code></a> and used by <a href="#val-temp_file"><code>Filename.temp_file</code></a> and <a href="#val-open_temp_file"><code>Filename.open_temp_file</code></a>. The temporary directory is a domain-local value which is inherited by child domains.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-quote"><a href="#val-quote" class="anchor"></a><code><span><span class="keyword">val</span> quote : <span>string <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><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></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-quote_command"><a href="#val-quote_command" class="anchor"></a><code><span><span class="keyword">val</span> quote_command :
|
||
<span>string <span class="arrow">-></span></span>
|
||
<span>?stdin:string <span class="arrow">-></span></span>
|
||
<span>?stdout:string <span class="arrow">-></span></span>
|
||
<span>?stderr:string <span class="arrow">-></span></span>
|
||
<span><span>string list</span> <span class="arrow">-></span></span>
|
||
string</span></code></div><div class="spec-doc"><p><code>quote_command cmd args</code> returns a quoted command line, suitable for use as an argument to <a href="../Sys/index.html#val-command"><code>Sys.command</code></a>, <a href="../../Unix/index.html#val-system"><code>Unix.system</code></a>, and the <a href="../../Unix/index.html#val-open_process"><code>Unix.open_process</code></a> functions.</p><p>The string <code>cmd</code> is the command to call. The list <code>args</code> is the list of arguments to pass to this command. It can be empty.</p><p>The optional arguments <code>?stdin</code> and <code>?stdout</code> and <code>?stderr</code> are file names used to redirect the standard input, the standard output, or the standard error of the command. If <code>~stdin:f</code> is given, a redirection <code>< f</code> is performed and the standard input of the command reads from file <code>f</code>. If <code>~stdout:f</code> is given, a redirection <code>> f</code> is performed and the standard output of the command is written to file <code>f</code>. If <code>~stderr:f</code> is given, a redirection <code>2> f</code> is performed and the standard error of the command is written to file <code>f</code>. If both <code>~stdout:f</code> and <code>~stderr:f</code> are given, with the exact same file name <code>f</code>, a <code>2>&1</code> redirection is performed so that the standard output and the standard error of the command are interleaved and redirected to the same file <code>f</code>.</p><p>Under Unix and Cygwin, the command, the arguments, and the redirections if any are quoted using <a href="#val-quote"><code>Filename.quote</code></a>, then concatenated. Under Win32, additional quoting is performed as required by the <code>cmd.exe</code> shell that is called by <a href="../Sys/index.html#val-command"><code>Sys.command</code></a>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Failure</span> <p>if the command cannot be escaped on the current platform.</p></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.10.0</li></ul></div></div></div></body></html> |