使用 PHP 获取目录的层次结构
我正在尝试查找指定目录下的所有文件和文件夹
例如我有 /home/user/stuff
我想返回
/home/user/stuff/folder1/image1.jpg
/home/user/stuff/folder1/image2.jpg
/home/user/stuff/folder2/subfolder1/image1.jpg
/home/user/stuff/image1.jpg
希望这是有道理的!
I'm trying to find all the files and folders under a specified directory
For example I have /home/user/stuff
I want to return
/home/user/stuff/folder1/image1.jpg
/home/user/stuff/folder1/image2.jpg
/home/user/stuff/folder2/subfolder1/image1.jpg
/home/user/stuff/image1.jpg
Hopefully that makes sense!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
工作解决方案(更改为您的文件夹名称)
The working solution (change with your folder name)
查找指定目录下的所有文件和文件夹。
输出(示例):
Find all the files and folders under a specified directory.
Output (example) :
除了
RecursiveDirectoryIterator
解决方案之外,还有glob()
解决方案:
Beside
RecursiveDirectoryIterator
solution there is alsoglob()
solution:您可以使用 RecursiveDirectoryIterator 甚至 glob 函数。
或者,scandir 函数也可以完成这项工作。
You can use the RecursiveDirectoryIterator or even the glob function.
Alternatively, the scandir function will do the job.