List all files in a directory ,extra information is coming

你说的曾经没有我的故事 提交于 2019-12-02 15:59:04

问题


here my code-

if ($handle = opendir('banner/')) {    
    while (false !== ($file = readdir($handle))) { 
        echo "$file"; 
    }     
    closedir($handle); 
} 

wher I run this code unnecessary dots(.) are coming. output image-3.jpgimage-4.jpgimage-1.jpgimage-2.jpgimage-5.jpg... why 3 dots are coming at the last??


回答1:


Because . is the current directory and .. is the parent directory.

They are always exists.

If you need to exclude them - just add

if ($file != '.' && $file != '..')

right before echo




回答2:


It's because there are items in your directory which you don't see... one of them is . and represents the current directory, and the other is .. and represents the directory above the current one. You need to filter these out of any readdir results.



来源:https://stackoverflow.com/questions/4164742/list-all-files-in-a-directory-extra-information-is-coming

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!