path.html
来自「perl教程」· HTML 代码 · 共 131 行
HTML
131 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>File::Path - create or remove directory trees</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>File::Path - create or remove directory trees</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#diagnostics">DIAGNOSTICS</a></li>
<li><a href="#authors">AUTHORS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>File::Path - create or remove directory trees</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">File::Path</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">mkpath</span><span class="operator">(</span><span class="operator">[</span><span class="string">'/foo/bar/baz'</span><span class="operator">,</span> <span class="string">'blurfl/quux'</span><span class="operator">]</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0711</span><span class="operator">);</span>
<span class="variable">rmtree</span><span class="operator">(</span><span class="operator">[</span><span class="string">'foo/bar/baz'</span><span class="operator">,</span> <span class="string">'blurfl/quux'</span><span class="operator">]</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <code>mkpath</code> function provides a convenient way to create directories, even
if your <a href="../../lib/Pod/perlfunc.html#item_mkdir"><code>mkdir</code></a> kernel call won't create more than one level of directory at
a time. <code>mkpath</code> takes three arguments:</p>
<ul>
<li>
<p>the name of the path to create, or a reference
to a list of paths to create,</p>
</li>
<li>
<p>a boolean value, which if TRUE will cause <code>mkpath</code>
to print the name of each directory as it is created
(defaults to FALSE), and</p>
</li>
<li>
<p>the numeric mode to use when creating the directories
(defaults to 0777), to be modified by the current umask.</p>
</li>
</ul>
<p>It returns a list of all directories (including intermediates, determined
using the Unix '/' separator) created.</p>
<p>If a system error prevents a directory from being created, then the
<code>mkpath</code> function throws a fatal error with <code>Carp::croak</code>. This error
can be trapped with an <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a> block:</p>
<pre>
<span class="keyword">eval</span> <span class="operator">{</span> <span class="variable">mkpath</span><span class="operator">(</span><span class="variable">$dir</span><span class="operator">)</span> <span class="operator">};</span>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">$@</span><span class="operator">)</span> <span class="operator">{</span>
<span class="keyword">print</span> <span class="string">"Couldn't create $dir: $@"</span><span class="operator">;</span>
<span class="operator">}</span>
</pre>
<p>Similarly, the <code>rmtree</code> function provides a convenient way to delete a
subtree from the directory structure, much like the Unix command <code>rm -r</code>.
<code>rmtree</code> takes three arguments:</p>
<ul>
<li>
<p>the root of the subtree to delete, or a reference to
a list of roots. All of the files and directories
below each root, as well as the roots themselves,
will be deleted.</p>
</li>
<li>
<p>a boolean value, which if TRUE will cause <code>rmtree</code> to
print a message each time it examines a file, giving the
name of the file, and indicating whether it's using <a href="../../lib/Pod/perlfunc.html#item_rmdir"><code>rmdir</code></a>
or <a href="../../lib/Pod/perlfunc.html#item_unlink"><code>unlink</code></a> to remove it, or that it's skipping it.
(defaults to FALSE)</p>
</li>
<li>
<p>a boolean value, which if FALSE (the default for non-root users) will
cause <code>rmtree</code> to adjust the mode of directories (if required) prior
to attempting to remove the contents. Note that on interruption or
failure of <code>rmtree</code>, directories may be left with more permissive
modes for the owner.</p>
</li>
</ul>
<p>It returns the number of files successfully deleted. Symlinks are
simply deleted and not followed.</p>
<p>
</p>
<hr />
<h1><a name="diagnostics">DIAGNOSTICS</a></h1>
<ul>
<li>
<p>On Windows, if <code>mkpath</code> gives you the warning: <strong>No such file or
directory</strong>, this may mean that you've exceeded your filesystem's
maximum path length.</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>Tim Bunce <<em><a href="mailto:Tim.Bunce@ig.co.uk">Tim.Bunce@ig.co.uk</a></em>> and
Charles Bailey <<em><a href="mailto:bailey@newman.upenn.edu">bailey@newman.upenn.edu</a></em>></p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?