使用php列出目录中的所有文件夹子文件夹和文件 [英] Listing all the folders subfolders and files in a directory using php

查看:79
本文介绍了使用php列出目录中的所有文件夹子文件夹和文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给我一个使用php列出目录中所有文件夹,子文件夹,文件的解决方案.我的文件夹结构是这样的:

Please give me a solution for listing all the folders,subfolders,files in a directory using php. My folder structure is like this:

Main Dir
 Dir1
  SubDir1
   File1
   File2
  SubDir2
   File3
   File4
 Dir2
  SubDir3
   File5
   File6
  SubDir4
   File7
   File8

我想获取每个文件夹中所有文件的列表.

I want to get the list of all the files inside each folder.

php中是否有任何shell脚本命令?

推荐答案

function listFolderFiles($dir){
    $ffs = scandir($dir);

    unset($ffs[array_search('.', $ffs, true)]);
    unset($ffs[array_search('..', $ffs, true)]);

    // prevent empty ordered elements
    if (count($ffs) < 1)
        return;

    echo '<ol>';
    foreach($ffs as $ff){
        echo '<li>'.$ff;
        if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
        echo '</li>';
    }
    echo '</ol>';
}

listFolderFiles('Main Dir');

这篇关于使用php列出目录中的所有文件夹子文件夹和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆