遍历目录操作
时间:2007-11-02 来源:phpoop
?php
//遍历目录操作
$handle = @opendir("D:\\usr\\webroot\\test\\file");
//遍历目录,方法一
if ($handle) {
echo "目录下文件:\n";
while (false !==($file = readdir($handle))){
echo "$file \n";
}
} else {
echo "Error!";
}
//方法二 Directory类遍历目录
/*
Directory类是内建类,包含2个属性和3个方法
class Directory {
string $path
resourse $handle
string read()
void rewind()
void close()
}
*/
$dir = dir("D:\\usr\\webroot\\test");
echo "Handle:"."$dir->handle"."\n";
echo "Path:"."$dir->path"."\n";
while (false !==($file = $dir->read())){
echo "$file \n";
}
$dir->close;
?>
相关阅读 更多 +