# PHP函数:dir()

**URL:** <https://www.isharkfly.com/t/php-dir/4591>\
**Category:** PHP\
**Created:** [October 8, 2012, 4:27pm UTC](https://www.isharkfly.com/t/php-dir/4591 "2012-10-08T16:27:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [October 8, 2012, 4:27pm UTC](https://www.isharkfly.com/t/php-dir/4591/1 "2012-10-08T16:27:17Z")

</div>

dir

目录类别类。

语法: new dir(string directory);

返回值: 类

函数种类: 文件存取

内容说明

这是一个类似面向对象的类别类，用来读取目录。当目录参数 directory 打开之后，有二个属性可用：handle 属性就像其它非类的函数所用的 readdir()、rewinddir() 及 closedir()；path 属性则配置打开目录后的路径参数。本类有三个方法 (method)：read、rewind 与 close。

使用范例

\<? $d = dir("/etc"); echo "Handle: ".$d-\>handle."  
\n"; echo "Path: ".$d-\>path."  
\n"; while($entry=$d-\>read()) { echo $entry."  
\n"; } $d-\>close(); ?\>
