Last active
October 13, 2018 17:36
-
-
Save k-msalehi/9fc835f73a12dfe8784cf1db60a992b9 to your computer and use it in GitHub Desktop.
Count number of lines by suffix of files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* get files in folders and subfolders with $extensions extensions in $path. | |
* @param array $extentios | |
* @param string $path optinal. default is path of execution directory | |
*/ | |
//default path is current directory and sub directories | |
function listFolderFiles($extensions ,$path = '.') | |
{ | |
//files to count line numbers sort in $files | |
static $files; | |
//extensions of files that you will count line numbers | |
$extensions = ['php']; | |
foreach (new DirectoryIterator($path) as $fileInfo) { | |
if (!$fileInfo->isDot()) { | |
if (in_array($fileInfo->getExtension(), $extensions)) { | |
$files[] = $fileInfo->getPathname(); | |
} | |
if ($fileInfo->isDir()) { | |
listFolderFiles($fileInfo->getPathname()); | |
} | |
} | |
} | |
return $files; | |
} | |
function counter($extensions, $path = '.') | |
{ | |
$counter = 0; | |
$files = (listFolderFiles($extensions,$path)); | |
foreach ($files as $key) { | |
$counter = $counter + count(file($key)); | |
} | |
return $counter; | |
} | |
//usage | |
echo counter(['php','css',], 'path/to/dir'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment