[英]RecursiveDirectoryIterator constructor returns empty object
I have a problem with the following line: 我对以下行有疑问:
$iterator = new RecursiveDirectoryIterator($directory);
This code returns an empty object even though the $directory folder contains at least one file. 即使$ directory文件夹包含至少一个文件,此代码也将返回一个空对象。 I also double checked the value of $directory and it's the right path
我还仔细检查了$ directory的值,它是正确的路径
What could be the problem? 可能是什么问题呢?
Try to use a foreach, because print_f will output empty object even if the object is not empty. 尝试使用foreach,因为即使对象不为空,print_f也会输出空对象。 You can check this out like that:
您可以像这样检查:
foreach ($iterator as $name => $file) {
echo $file->getRealPath().'<br>';
}
Try this, 尝试这个,
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST
);
It should get you a file list or throw an exception. 它应该为您提供文件列表或引发异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.