<?php

function countDirectories($directory) {
    $dirCount = 0;
    
    if ($handle = opendir($directory)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
                $path = $directory . '/' . $entry;
                if (is_dir($path)) {
                    $dirCount++;
                }
            }
        }
        closedir($handle);
    }
    
    return $dirCount;
}

$baseDir = __DIR__;
$outputFile = __DIR__ . '/dir_count.txt';

// Očisti fajl ako postoji
file_put_contents($outputFile, '');

// Pročitaj sve godine
if ($handle = opendir($baseDir)) {
    while (false !== ($year = readdir($handle))) {
        if ($year != "." && $year != ".." && is_dir($baseDir . '/' . $year)) {
            $yearPath = $baseDir . '/' . $year;
            
            // Pročitaj sve mesece u godini
            if ($monthHandle = opendir($yearPath)) {
                while (false !== ($month = readdir($monthHandle))) {
                    if ($month != "." && $month != ".." && is_dir($yearPath . '/' . $month)) {
                        $monthPath = $yearPath . '/' . $month;
                        $count = countDirectories($monthPath);
                        $result = "$year -> $month: $count\n";
                        file_put_contents($outputFile, $result, FILE_APPEND);
                    }
                }
                closedir($monthHandle);
            }
        }
    }
    closedir($handle);
}
?> 