Jump to content

[SOLVED] Count # of lines of all PHP files in a directory?


LooieENG

Recommended Posts

this should work:

 

<?php
  function count_lines ( $dir ) {
    if(!($dir = realpath($dir))) return false;
    if(is_dir($dir)){
      $lines = 0;
      foreach(scandir($dir) as $file){
        if($file{0} == '.') continue;
        $lines += count_lines($dir.DIRECTORY_SEPARATOR.$file);
      }
    }else
      $lines = count(file($dir));
    return $lines;
  }
  print number_format(count_lines('.')).' lines';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.