-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.php
More file actions
42 lines (31 loc) · 906 Bytes
/
Copy pathapp.php
File metadata and controls
42 lines (31 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
$path = __DIR__ . '/test';
print_r('Scan dir: ' . $path . PHP_EOL);
$directory = new RecursiveDirectoryIterator(__DIR__ . '/test');
$iterator = new RecursiveIteratorIterator($directory);
// Calc summ in file lines
function getSummFromFile(SplFileObject $file) {
$fileSumm = 0;
while (!$file->eof()) {
$line = $file->fgets();
if (empty(trim($line))) {
continue;
}
$fileSumm += (float) str_replace(',', '.', $line);
}
return $fileSumm;
}
$totalSumm = 0;
foreach(iterator_to_array($iterator) as $fileInfo) {
if (!$fileInfo->isFile()) {
continue;
}
if (!$fileInfo->isReadable()) {
continue;
}
if ($fileInfo->getFilename() === 'count') {
$file = $fileInfo->openFile();
$totalSumm += getSummFromFile($file);
}
}
echo 'Summ "count" file values: ' . $totalSumm . PHP_EOL;