我想在一个目录中的一组文件夹上做一个 RecursiveDirectoryIterator ,./temp
然后根据文件夹的名称列出每个文件夹中的文件。
例如,我有文件夹A
和B
.
在 A 中,我有一个文件列表,例如, 1.txt
, 2.php
, 2.pdf
, .3.doc
3.pdf
在 B 中,我有1.pdf
, 1.jpg
, 2.png
.
我希望我的结果是这样的:
A => List of files in A
B => List of files in B
如何才能做到这一点?
<?php
$scan_it = new RecursiveDirectoryIterator("./temp");
foreach(new RecursiveIteratorIterator($scan_it) as $file =>$key) {
$filetypes = array("pdf");
$filetype = pathinfo($file, PATHINFO_EXTENSION);
if (in_array(strtolower($filetype), $filetypes)) {
$dlist=basename($file); //sort
?>
<ul>
<li>
<?php echo substr(dirname($file),11);?>
</li>
<li>
<a href="<?php echo $file;?>"><?php echo basename($file);?></a>
</li>
</ul>
<?php
}}
?>