PHP DirectoryIterator 帮助
在下面的代码中,可以调用什么来代替->getFilename()
?
<?php
foreach (new DirectoryIterator('../moodle') as $fileInfo) {
if($fileInfo->isDot()) continue;
echo $fileInfo->getFilename() . "<br>\n";
}
?>
PS,我已经看过文档了。请不要链接到此处。
感谢您的帮助。
编辑:
发布此内容后,我意识到文档中有答案。我真正的问题是,其他方法有什么作用?文件在这方面似乎受到限制。
In the following code, what can be called instead of ->getFilename()
?
<?php
foreach (new DirectoryIterator('../moodle') as $fileInfo) {
if($fileInfo->isDot()) continue;
echo $fileInfo->getFilename() . "<br>\n";
}
?>
PS, I have seen the documentation. Please don't link to here.
Thanks for the help.
EDIT:
After posting this I realized that the Docs had the answer. My real question becomes, what do the other methods do? The Docs seem to be limited in regards to that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
糟糕,误读了您的代码。除了文件名之外,您到底想要什么?您已经看过文档,所以您知道有完整路径(
getPathname
)和仅包含目录的路径(getPath
)的方法...我不确定什么你想要在这里...我假设你想要
.
或..
的目录名称,这样你就可以使用getPath
然后弹出关闭最后一个/倒数第二个段,或者您可以只使用dirname($fileInfo->getPathname())
EDIT:
Oops misread your code. What exactly are you after instead of the filename? youve seen the docs so you know there are methods for both the full path (
getPathname
) and just the path to the containing dir (getPath
)... Im not sure what you want here...I assume you want the directory name of
.
or..
so to get that you could usegetPath
and then pop the last/second-to-last segment off or you could just usedirname($fileInfo->getPathname())