📄 class.dir.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Return an instance of the Directory class</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.chroot.html">chroot</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.closedir.html">closedir</a></div> <div class="up"><a href="ref.dir.html">Directory Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="class.dir" class="refentry"> <div class="refnamediv"> <h1 class="refname">dir</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">dir</span> — <span class="dc-title">Return an instance of the Directory class</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="classsynopsis"> <div class="ooclass"><b class="classname">Directory</b></div> <div class="classsynopsisinfo"> <span class="ooclass"> <b class="classname">Directory</b> </span> {</div> <div class="fieldsynopsis"> <span class="type">string</span> <var class="varname">$path</var> ;</div> <div class="fieldsynopsis"> <span class="type">resource</span> <var class="varname">$handle</var> ;</div> <div class="methodsynopsis dc-description"><span class="type">string</span> <span class="methodname"><b><b>Directory::read</b></b></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"><span class="type">void</span> <span class="methodname"><b><b>Directory::rewind</b></b></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"><span class="type">void</span> <span class="methodname"><b><b>Directory::close</b></b></span> ( <span class="methodparam">void</span> )</div> }</div> <p class="para"> A pseudo-object oriented mechanism for reading a directory. The given <i><tt class="parameter">directory</tt></i> is opened. Two properties are available once the directory has been opened. The handle property can be used with other directory functions such as <a href="function.readdir.html" class="function">readdir()</a>, <a href="function.rewinddir.html" class="function">rewinddir()</a> and <a href="function.closedir.html" class="function">closedir()</a>. The path property is set to path the directory that was opened. Three methods are available: read, rewind and close. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>dir()</b> example</b></p> <div class="example-contents"><p> Please note the fashion in which <b>dir::read()</b>'s return value is checked in the example below. We are explicitly testing whether the return value is identical to (equal to and of the same type as - see <a href="language.operators.comparison.html" class="link"> Comparison Operators</a> for more information) <b><tt>FALSE</tt></b> since otherwise, any directory entry whose name evaluates to <b><tt>FALSE</tt></b> will stop the loop. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$d </span><span style="color: #007700">= </span><span style="color: #0000BB">dir</span><span style="color: #007700">(</span><span style="color: #DD0000">"/etc/php5"</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Handle: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$d</span><span style="color: #007700">-></span><span style="color: #0000BB">handle </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"Path: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$d</span><span style="color: #007700">-></span><span style="color: #0000BB">path </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">false </span><span style="color: #007700">!== (</span><span style="color: #0000BB">$entry </span><span style="color: #007700">= </span><span style="color: #0000BB">$d</span><span style="color: #007700">-></span><span style="color: #0000BB">read</span><span style="color: #007700">())) {<br /> echo </span><span style="color: #0000BB">$entry</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$d</span><span style="color: #007700">-></span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>Handle: Resource id #2Path: /etc/php5...apachecgicli</pre></div> </pre></div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: The order in which directory entries are returned by the read method is system-dependent. <br /> </p></blockquote> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.chroot.html">chroot</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.closedir.html">closedir</a></div> <div class="up"><a href="ref.dir.html">Directory Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -