====== line counter ====== ===== php ===== \n\n"); $dir = $argv[1]; $countExtReg = implode($countExtensions, "|"); $lineCount = 0; function processDir($dirname){ global $countExtReg, $lineCount; if( !($dh = opendir($dirname)) ) return; $oldDir = getcwd(); chdir($dirname); while( false !== ($file = readdir($dh)) ){ // skip current and previous references if( preg_match("/^\.|^\.\./", $file) != 0 ) continue; // compare against programming extensions if( preg_match("/^.*\.($countExtReg)$/i", $file) != 0 ){ echo realpath($file) . "\n"; $lines = file($file); $lineCount += count($lines); unset($lines); } if( is_dir($file) ) processDir($file); } closedir($dh); chdir($oldDir); } if( !is_dir($dir) ) exit("\n$dir is not a directory\n"); processDir($dir); exit("\nLine Count: $lineCount\n\n"); ?>