我这里有一个代码,该代码将计算php文件中所有文件的总数,大小和方法的数量。这些文件位于文件夹内,并具有子目录
class fileScanner
{
private $aFileProperties;
public function scanDir($path)
{
$ite = new RecursiveDirectoryIterator($path);
$bytestotal= 0;
$nbfiles = 0;
$countMethods = 0;
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur ) {
$filesize = $cur->getSize();
$files = str_replace('\\','/', $filename);
$bytestotal += $filesize;
$countMethods += count($this->getMethods($files));
$nbfiles++;
}
$bytestotal = number_format($bytestotal);
$this->aFileProperties = [
'total_files' => $nbfiles,
'total_size' => $bytestotal,
'methods' => $countMethods
];
return;
}
public function getMethods($sFilepath) {
$sCode = file_get_contents($sFilepath);
$methods = $this->getMethodsInFile($sCode);
return $methods;
}
public function getMethodsInFile($sFile) {
$methods = array();
$tokens = token_get_all($sFile);
$count = count($tokens);
for ($i = 2; $i < $count; $i++) {
if ($tokens[$i-2][0] === T_FUNCTION
&& $tokens[$i-1][0] === T_WHITESPACE &&
$tokens[$i][0] === T_STRING) {
$phpMethod = $tokens[$i][1];
$methods[] = $phpMethod;
}
}
return $methods;
}
public function getFileProperties()
{
return $this->aFileProperties;
}
}
$scan = new fileScanner;
$scan->scanDir('./csd4');
$files = $scan->getFileProperties();
但是在运行代码时,我说了一个错误
第35行的C:\ xampp \ htdocs \ file-scanner \ index.php中的权限被拒绝
任何想法我该如何解决?我尝试了file_get_content的其他替代方法,但是我仍然遇到相同的错误。我已经检查了权限,并且拥有对该文件夹的完全控制权