繁体   English   中英

在PHP中,为什么我的scandir调用返回错误数量的文件?

[英]In PHP, why does my scandir call return the wrong amount of files?

    for($instancesFiles=1;$instancesFiles<count(scandir("Articles/".date('y-m-d').""));$instancesFiles++){
//For each file inside the directory for today's articles, each of which corresponds to an instance of the "article" class...
        $dir="Articles/".date("y-m-d")."/".$instancesFiles."";
        $artProps=scandir($dir);
    //Retrieve an array of its interior files, each of which corresponds to a property of the aforementioned instance

在今天的日期文件下,我还有一个其他目录,但是当要求对scandir返回的数组进行计数时,我总是得到“ 3”。(我已经用echo调用进行了检查,其中“ count(scandir($ dir))“始终返回3. $ dir中有子文件,但是有4个子文件。可能与此有关吗?如何解决此错误?感谢您提供的任何帮助;我非常感谢从有经验的程序员的建议。:)

使用scandir,您总是可以得到当前目录(。)和父目录(..)。 您可以检查是否将scandir的结果制成print_r。 因此,您只需要减去scandir的计数2。

根据文档:

$dir    = '/tmp';
$files1 = scandir($dir);

print_r($files1);

Array
(
    [0] => .
    [1] => ..
    [2] => bar.php
    [3] => foo.txt
    [4] => somedir
)

$ dir中有子文件,但有4个子文件。 可能与这有关吗?

=>不,scandir不是递归的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM