Aggiunta possibilità di definire delle esclusioni per folderSize

This commit is contained in:
Luca 2020-06-26 16:26:42 +02:00
parent 830378b812
commit 8c8d379582
2 changed files with 4 additions and 3 deletions

View File

@ -148,7 +148,7 @@ switch (filter('op')) {
]; ];
foreach ($dirs as $dir => $description) { foreach ($dirs as $dir => $description) {
$size = FileSystem::folderSize($dir); $size = FileSystem::folderSize($dir, ['htaccess']);
$results[] = [ $results[] = [
'description' => $description, 'description' => $description,

View File

@ -45,14 +45,15 @@ class FileSystem
* *
* @return int * @return int
*/ */
public static function folderSize($path) public static function folderSize($path, $exclusions = array())
{ {
$total = 0; $total = 0;
$path = realpath($path); $path = realpath($path);
if ($path !== false && $path != '' && file_exists($path)) { if ($path !== false && $path != '' && file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
$total += $object->getSize(); if (!in_array($object->getExtension(), $exclusions))
$total += $object->getSize();
} }
} }