<?php
// NOTE: change the following to the right directory path on server
$basePath = '../';

function dirToArray(string $dir): array
{
   $result = [];

   $cdir = scandir($dir);
   foreach ($cdir as $key => $value)
   {
      if (!in_array($value, ['maintenance', 'filelist.json', 'LICENSE']) && (strpos($value, '.') !== 0)) {
         if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
            $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
         } else {
            $result[] = [
		'size_bytes' => filesize($dir . DIRECTORY_SEPARATOR . $value),
		'name'       => $value,
	    ];
         }
      }
   }

   return $result;
}

$dirs = dirToArray($basePath);

file_put_contents($basePath . 'filelist.json',  json_encode($dirs, JSON_PRETTY_PRINT));
echo "\nok\n\n";
