dqwh1205 2014-08-25 19:35
浏览 26
已采纳

获取文件和文件夹计数

In my lyrics application, I'm using a multi-dimensional array to print the artists and album/track counts.

$test_arr = [
    /* artist               albums  tracks */
    [ "Green Day",          "8",    "26",   ],
    [ "Remy Zero",          "1",    "2",    ],
    [ "System of a Down",   "1",    "1",    ],
    [ "Modern Talking",     "1",    "1",    ],
    [ "Snow Patrol",        "1",    "2",    ],
    [ "Linkin Park",        "6",    "18",   ],
    [ "3 Doors Down",       "5",    "13",   ],
    /* ... */
];

In the array, I enter the album and track counts manually. I don't want to do that. Is there a way to add them with PHP?

Take 3 Doors Down for example. If I go to folder properties of 3 Doors Down, there I can see:

Contains:   13 Files, 5 Folders

and the folder tree of 3 Doors Down

...\3_doors_down
+---2000_the_better_life
|       01_kryptonite.txt
|       03_duck_and_run.txt
|       05_be_like_that.txt
|       11_so_i_need_you.txt
|       
+---2002_away_from_the_sun
|       06_here_without_you.txt
|       09_changes.txt
|       
+---2005_seventeen_days
|       03_let_me_go.txt
|       07_behind_those_eyes.txt
|       12_here_by_me.txt
|       
+---2008_3_doors_down
|       03_its_not_my_time.txt
|       05_pages.txt
|       
\---2011_time_of_my_life
        08_whats_left.txt
        12_believer.txt

Is there a way to count the total folders and files in a given directory?

  • 写回答

1条回答 默认 最新

  • dongxiangxie8181 2014-08-25 20:01
    关注

    To count all files and folders in a directory:

    count( glob( 'directory/*' ) );
    

    To just count directories:

    $i = 0;
    $ps = glob( 'directory/*' );
    foreach( $ps as $p )
    {
        if( is_dir( $p ) )
            $i++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来