我有这个结构的目录:使用RecursiveDirectoryIterator将目录和文件列入数组?
- 主/
- | - 图像/
- | - file1.jpg
- | - file2.jpg
- | - - file3.jpg
- | - 文件/
- | - 私人/
- | --- blahblahblah.docx
- | - Test.doc的
- | - TEST.XLS
- | - test.txt的
- | - 私人/
- | - 图像/
我可以创建一个函数来完成工作,但RecursiveDirectoryIterator类更快,内存使用量更少。如何使用RecursiveDirectoryIterator列出这些目录到像这样的数组:
array(
"main/" => array(
"images/" => array(
"file1.jpg",
"file2.jpg",
"file3.jpg"
),
"documents/" => array(
"private/" => array(
"blahblahblah.docx"
),
"test.doc",
"test.xls",
"test.txt"
)
)
)
出于好奇,为什么你真的想要转换到嵌套*数组a *的树查看器?你打算如何处理这个数组,你无法通过迭代遍历这些目录? – Gordon 2010-08-24 14:55:44
我只是想将目录的信息转换为嵌套数组:) – user366124 2010-08-24 16:06:56
是的,但是为了什么目的?一旦拥有它,你将如何处理阵列?如果你没有做任何事情,这是毫无意义的要求。我问的原因是因为如果它只是一个中间格式,并且直接从Iterator转到您想要对数组执行操作,那么您可能会跳过多dim数组。 – Gordon 2010-08-24 16:26:57