main->filesPath; rename($filesPath . DS . $name, $dir . DS . $name); }; break; case '-purge': $func = function($name) use ($dir) { echo $name . PHP_EOL; static $filesPath = null; if ($filesPath == null) $filesPath = configFactory()->main->filesPath; unlink($filesPath . DS . $name); }; break; default: die('Unknown action' . PHP_EOL); } $names = []; foreach (R::findAll('post') as $post) { $names []= $post->name; } $names = array_flip($names); $config = configFactory(); $filesPath = $config->main->filesPath; foreach (glob($filesPath . DS . '*') as $name) { $name = basename($name); if (!isset($names[$name])) { $func($name); } }