dpb_4431 2013-07-29 00:48
浏览 225

php中函数readdir()的返回值中的单点和双点是什么?

I've been confused with the concept which descriped in php.net for the function is_dir(),it says

Tells whether the given filename is a directory

(1)It checks whether the given parameter is a directory or not,when I give it a path,it returns true on success,but it uses the term given filename,if I know it is filename(file returns false),why would I bothering checking it in the first place?

(2)Here comes the spot where I've been confused of,readdir returns the files resides inside the given folder,it returns the file names but also returns single dot and double dots while I looping the opendir(),so,what exactly does the dots means in the return value?

  • 写回答

1条回答 默认 最新

  • dtrovwl75780 2013-07-29 01:07
    关注

    Its very simple i think.
    The singe dot represents the current directory and the double dot the parent directory.
    In the root directory there would be no double dot.
    If you use the "ls -a" Linux command there will be the same output (single and double dot).
    This is very useful in some cases to be able to see which permissions are given in the parent or the current directory.
    I don't know it for sure, but i think the readdir function uses the same interface which causes the the dots. (maybe php simply uses the "ls" statement internally or something like that)

    you could simply skip this two "files" in a loop with something like:

    if ($file == "." or $file == "..") continue;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大