mac.html

来自「perl教程」· HTML 代码 · 共 530 行 · 第 1/2 页

HTML
530 行
字号
<dt><strong><a name="item_curdir">curdir</a></strong>

<dd>
<p>Returns a string representing the current directory. On Mac OS, this is &quot;:&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_devnull">devnull</a></strong>

<dd>
<p>Returns a string representing the null device. On Mac OS, this is &quot;Dev:Null&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_rootdir">rootdir</a></strong>

<dd>
<p>Returns a string representing the root directory.  Under MacPerl,
returns the name of the startup volume, since that's the closest in
concept, although other volumes aren't rooted there. The name has a
trailing &quot;:&quot;, because that's the correct specification for a volume
name on Mac OS.</p>
</dd>
<dd>
<p>If Mac::Files could not be loaded, the empty string is returned.</p>
</dd>
</li>
<dt><strong><a name="item_tmpdir">tmpdir</a></strong>

<dd>
<p>Returns the contents of $ENV{TMPDIR}, if that directory exits or the
current working directory otherwise. Under MacPerl, $ENV{TMPDIR} will
contain a path like &quot;MacintoshHD:Temporary Items:&quot;, which is a hidden
directory on your startup volume.</p>
</dd>
</li>
<dt><strong><a name="item_updir">updir</a></strong>

<dd>
<p>Returns a string representing the parent directory. On Mac OS, this is &quot;::&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_file_name_is_absolute">file_name_is_absolute</a></strong>

<dd>
<p>Takes as argument a path and returns true, if it is an absolute path.
If the path has a leading &quot;:&quot;, it's a relative path. Otherwise, it's an
absolute path, unless the path doesn't contain any colons, i.e. it's a name
like &quot;a&quot;. In this particular case, the path is considered to be relative
(i.e. it is considered to be a filename). Use &quot;:&quot; in the appropriate place
in the path if you want to distinguish unambiguously. As a special case,
the filename '' is always considered to be absolute. Note that with version
1.2 of File::Spec::Mac, this does no longer consult the local filesystem.</p>
</dd>
<dd>
<p>E.g.</p>
</dd>
<dd>
<pre>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">file_name_is_absolute</span><span class="operator">(</span><span class="string">"a"</span><span class="operator">);</span>             <span class="comment"># false (relative)</span>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">file_name_is_absolute</span><span class="operator">(</span><span class="string">":a:b:"</span><span class="operator">);</span>         <span class="comment"># false (relative)</span>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">file_name_is_absolute</span><span class="operator">(</span><span class="string">"MacintoshHD:"</span><span class="operator">);</span>  <span class="comment"># true (absolute)</span>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">file_name_is_absolute</span><span class="operator">(</span><span class="string">""</span><span class="operator">);</span>              <span class="comment"># true (absolute)</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_path">path</a></strong>

<dd>
<p>Returns the null list for the MacPerl application, since the concept is
usually meaningless under Mac OS. But if you're using the MacPerl tool under
MPW, it gives back $ENV{Commands} suitably split, as is done in
:lib:ExtUtils:MM_Mac.pm.</p>
</dd>
</li>
<dt><strong><a name="item_splitpath">splitpath</a></strong>

<dd>
<pre>
    <span class="operator">(</span><span class="variable">$volume</span><span class="operator">,</span><span class="variable">$directories</span><span class="operator">,</span><span class="variable">$file</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">splitpath</span><span class="operator">(</span> <span class="variable">$path</span> <span class="operator">);</span>
    <span class="operator">(</span><span class="variable">$volume</span><span class="operator">,</span><span class="variable">$directories</span><span class="operator">,</span><span class="variable">$file</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">splitpath</span><span class="operator">(</span> <span class="variable">$path</span><span class="operator">,</span> <span class="variable">$no_file</span> <span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Splits a path into volume, directory, and filename portions.</p>
</dd>
<dd>
<p>On Mac OS, assumes that the last part of the path is a filename unless
$no_file is true or a trailing separator &quot;:&quot; is present.</p>
</dd>
<dd>
<p>The volume portion is always returned with a trailing &quot;:&quot;. The directory portion
is always returned with a leading (to denote a relative path) and a trailing &quot;:&quot;
(to denote a directory). The file portion is always returned <em>without</em> a leading &quot;:&quot;.
Empty portions are returned as empty string ''.</p>
</dd>
<dd>
<p>The results can be passed to <a href="#item_catpath"><code>catpath()</code></a> to get back a path equivalent to
(usually identical to) the original path.</p>
</dd>
<dt><strong><a name="item_splitdir">splitdir</a></strong>

<dd>
<p>The opposite of <a href="#item_catdir"><code>catdir()</code></a>.</p>
</dd>
<dd>
<pre>
    <span class="variable">@dirs</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">splitdir</span><span class="operator">(</span> <span class="variable">$directories</span> <span class="operator">);</span>
</pre>
</dd>
<dd>
<p>$directories should be only the directory portion of the path on systems
that have the concept of a volume or that have path syntax that differentiates
files from directories. Consider using <a href="#item_splitpath"><code>splitpath()</code></a> otherwise.</p>
</dd>
<dd>
<p>Unlike just splitting the directories on the separator, empty directory names
(<code>&quot;&quot;</code>) can be returned. Since <a href="#item_catdir"><code>catdir()</code></a> on Mac OS always appends a trailing
colon to distinguish a directory path from a file path, a single trailing colon
will be ignored, i.e. there's no empty directory name after it.</p>
</dd>
<dd>
<p>Hence, on Mac OS, both</p>
</dd>
<dd>
<pre>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">splitdir</span><span class="operator">(</span> <span class="string">":a:b::c:"</span> <span class="operator">);</span>    <span class="keyword">and</span>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">splitdir</span><span class="operator">(</span> <span class="string">":a:b::c"</span> <span class="operator">);</span>
</pre>
</dd>
<dd>
<p>yield:</p>
</dd>
<dd>
<pre>
    ( &quot;a&quot;, &quot;b&quot;, &quot;::&quot;, &quot;c&quot;)</pre>
</dd>
<dd>
<p>while</p>
</dd>
<dd>
<pre>
    <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">splitdir</span><span class="operator">(</span> <span class="string">":a:b::c::"</span> <span class="operator">);</span>
</pre>
</dd>
<dd>
<p>yields:</p>
</dd>
<dd>
<pre>
    ( &quot;a&quot;, &quot;b&quot;, &quot;::&quot;, &quot;c&quot;, &quot;::&quot;)</pre>
</dd>
</li>
<dt><strong><a name="item_catpath">catpath</a></strong>

<dd>
<pre>
    <span class="variable">$path</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">catpath</span><span class="operator">(</span><span class="variable">$volume</span><span class="operator">,</span><span class="variable">$directory</span><span class="operator">,</span><span class="variable">$file</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Takes volume, directory and file portions and returns an entire path. On Mac OS,
$volume, $directory and $file are concatenated.  A ':' is inserted if need be. You
may pass an empty string for each portion. If all portions are empty, the empty
string is returned. If $volume is empty, the result will be a relative path,
beginning with a ':'. If $volume and $directory are empty, a leading &quot;:&quot; (if any)
is removed form $file and the remainder is returned. If $file is empty, the
resulting path will have a trailing ':'.</p>
</dd>
<dt><strong><a name="item_abs2rel">abs2rel</a></strong>

<dd>
<p>Takes a destination path and an optional base path and returns a relative path
from the base path to the destination path:</p>
</dd>
<dd>
<pre>
    <span class="variable">$rel_path</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">abs2rel</span><span class="operator">(</span> <span class="variable">$path</span> <span class="operator">)</span> <span class="operator">;</span>
    <span class="variable">$rel_path</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">abs2rel</span><span class="operator">(</span> <span class="variable">$path</span><span class="operator">,</span> <span class="variable">$base</span> <span class="operator">)</span> <span class="operator">;</span>
</pre>
</dd>
<dd>
<p>Note that both paths are assumed to have a notation that distinguishes a
directory path (with trailing ':') from a file path (without trailing ':').</p>
</dd>
<dd>
<p>If $base is not present or '', then the current working directory is used.
If $base is relative, then it is converted to absolute form using <a href="#item_rel2abs"><code>rel2abs()</code></a>.
This means that it is taken to be relative to the current working directory.</p>
</dd>
<dd>
<p>If $path and $base appear to be on two different volumes, we will not
attempt to resolve the two paths, and we will instead simply return
$path.  Note that previous versions of this module ignored the volume
of $base, which resulted in garbage results part of the time.</p>
</dd>
<dd>
<p>If $base doesn't have a trailing colon, the last element of $base is
assumed to be a filename.  This filename is ignored.  Otherwise all path
components are assumed to be directories.</p>
</dd>
<dd>
<p>If $path is relative, it is converted to absolute form using <a href="#item_rel2abs"><code>rel2abs()</code></a>.
This means that it is taken to be relative to the current working directory.</p>
</dd>
<dd>
<p>Based on code written by Shigio Yamaguchi.</p>
</dd>
</li>
<dt><strong><a name="item_rel2abs">rel2abs</a></strong>

<dd>
<p>Converts a relative path to an absolute path:</p>
</dd>
<dd>
<pre>
    <span class="variable">$abs_path</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">rel2abs</span><span class="operator">(</span> <span class="variable">$path</span> <span class="operator">)</span> <span class="operator">;</span>
    <span class="variable">$abs_path</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-&gt;</span><span class="variable">rel2abs</span><span class="operator">(</span> <span class="variable">$path</span><span class="operator">,</span> <span class="variable">$base</span> <span class="operator">)</span> <span class="operator">;</span>
</pre>
</dd>
<dd>
<p>Note that both paths are assumed to have a notation that distinguishes a
directory path (with trailing ':') from a file path (without trailing ':').</p>
</dd>
<dd>
<p>If $base is not present or '', then $base is set to the current working
directory. If $base is relative, then it is converted to absolute form
using <a href="#item_rel2abs"><code>rel2abs()</code></a>. This means that it is taken to be relative to the
current working directory.</p>
</dd>
<dd>
<p>If $base doesn't have a trailing colon, the last element of $base is
assumed to be a filename.  This filename is ignored.  Otherwise all path
components are assumed to be directories.</p>
</dd>
<dd>
<p>If $path is already absolute, it is returned and $base is ignored.</p>
</dd>
<dd>
<p>Based on code written by Shigio Yamaguchi.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>See the authors list in <em>File::Spec</em>. Mac OS support by Paul Schinder
&lt;<a href="mailto:schinder@pobox.com">schinder@pobox.com</a>&gt; and Thomas Wegner &lt;<a href="mailto:wegner_thomas@yahoo.com">wegner_thomas@yahoo.com</a>&gt;.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (c) 2004 by the Perl 5 Porters.  All rights reserved.</p>
<p>This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p>See <a href="../../../lib/File/Spec.html">the File::Spec manpage</a> and <a href="../../../lib/File/Spec/Unix.html">the File::Spec::Unix manpage</a>.  This package overrides the
implementation of these methods, not the semantics.</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?