关于文件遍历的问题

WBOY
Release: 2016-06-23 13:35:47
Original
865 people have browsed it

function file_list($path)
{
$paths = iconv("UTF-8", "gb2312", $path);
if ($handle = opendir($paths))//打开路径成功
{
while (false !== ($file = readdir($handle)))//循环读取目录中的文件名并赋值给$file
{
echo $file.'
';
//在遍历每个文件目录时会输出 . .. 这三点是哪来的
if ($file != "." && $file != "..")//也就是这句判断的三点
{
if (is_dir($paths."/".iconv("gb2312","UTF-8",$file)))
{
// echo $path.": ".$file."
";//去掉此行显示的是所有的非目录文件
file_list($paths."/".iconv("gb2312","UTF-8",$file));
}
else
{
// echo $paths.": ".iconv("gb2312","UTF-8",$file)."
";
}
}
}
}
}
$path = "D:\A";
file_list($path);


回复讨论(解决方案)

if ($file != "." && $file != "..")//这三点是哪来的?
$file != "." 不是当前目录标志
$file != ".." 不是当前目录标志

目录在计算机的文件系统中也是文件,.和 .. 在目录文件中标识特定的目录项

linux下当前目录和上级目录

Related labels:
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
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!