LooieENG Posted May 7, 2008 Share Posted May 7, 2008 Any scripts that do this? I thought I'd found one but it gave an error. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/ Share on other sites More sharing options...
kenrbnsn Posted May 7, 2008 Share Posted May 7, 2008 We do not write code for you. If you have a script that is giving you problems, please post it and then we will help. Ken Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/#findComment-535328 Share on other sites More sharing options...
LooieENG Posted May 7, 2008 Author Share Posted May 7, 2008 Oh, nevermind then. I just thought there might already be one somebody knows about. Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/#findComment-535331 Share on other sites More sharing options...
rhodesa Posted May 7, 2008 Share Posted May 7, 2008 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'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/#findComment-535388 Share on other sites More sharing options...
LooieENG Posted May 7, 2008 Author Share Posted May 7, 2008 That worked perfect, thank you 395 lines for my blog so far Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/#findComment-535572 Share on other sites More sharing options...
kenrbnsn Posted May 8, 2008 Share Posted May 8, 2008 If you're running on a UNIX/Linux box, you can do: <?php list ($lc) = explode(' ',trim(exec('wc -l *.php'))); echo $lc . "\n"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/#findComment-535646 Share on other sites More sharing options...
LooieENG Posted May 9, 2008 Author Share Posted May 9, 2008 Thank you both Quote Link to comment https://forums.phpfreaks.com/topic/104587-solved-count-of-lines-of-all-php-files-in-a-directory/#findComment-537114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.