php目录管理函数小结_PHP教程

WBOY
Release: 2016-07-21 15:50:13
Original
895 people have browsed it

chdir : 改变目录。
dir : 目录类别类。
closedir : 关闭目录 handle。
opendir : 打开目录 handle。
readdir : 读取目录 handle。
rewinddir : 重设目录 handle。

chdir
改变目录。
语法: int chdir(string directory);
返回值: 整数
函数种类: 文件存取
内容说明 本函数用来改变目前 php 执行的目录到新的 directory 目录中。若无法改变则返回 false,成功则返回 true。

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();
?>

closedir
关闭目录 handle。
语法: void closedir(int dir_handle);
返回值: 无
函数种类: 文件存取
内容说明
本函数用来关闭目录资料流的 dir_handle。这个 dir_handle 参数所操作的目录必须要 opendir() 打开的方可使用。

opendir
打开目录 handle。
语法: int opendir(string path);
返回值: 整数
函数种类: 文件存取
内容说明
本函数用来打开目录资料流。返回的整数是可供其它目录函数操作的 handle。

readdir
读取目录 handle。
语法: string readdir(int dir_handle);
返回值: 字符串
函数种类: 文件存取
内容说明 本函数用来读取目录。返回目录中的文件名称,读取不照任何特殊的顺序。
使用范例 本例列出目前目录的所有文件
$handle=opendir('.');
echo "目录 handle: $handle\n";
echo "文件:\n";
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
?>

rewinddir
重设目录 handle。
语法: void rewinddir(int dir_handle);
返回值: 无
函数种类: 文件存取
内容说明 本函数用来重设目录资料流到开始处。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319394.htmlTechArticlechdir : 改变目录。 dir : 目录类别类。 closedir : 关闭目录 handle。 opendir : 打开目录 handle。 readdir : 读取目录 handle。 rewinddir : 重设目录 handle。...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!