美文网首页
PHP统计目录下全部行数

PHP统计目录下全部行数

作者: 长安猎人 | 来源:发表于2019-03-18 14:30 被阅读0次

统计目录行数

<?php
/**
 * Created by PhpStorm.
 * User: 21kr
 * Date: 2019/3/18
 * Time: 11:05
 */

class TongJi {

    private static $line = 0;
    private static $white_dir_list = ['storage', 'vendor', '.cache', 'node_modules', 'build', 'tests'];

    public static function readDirLine($file) {

        $list = scandir($file);
        foreach ($list as $_file) {
            if(is_dir($_file) && !in_array($_file, self::$white_dir_list) && strstr($_file, '.') === false) {
                self::readDirLine($_file);
            } else {
                if(is_file($_file)) {
                    self::$line += count(file($_file));
                }
            }
        }

        return self::$line;
    }

}

$line = TongJi::readDirLine('./');

相关文章

网友评论

      本文标题:PHP统计目录下全部行数

      本文链接:https://www.haomeiwen.com/subject/wkwauqtx.html