path("exports"); $files = glob($exportDir . "/export_*.zip"); if (empty($files)) { $this->info("No export files found."); return; } rsort($files); $keep = max(0, (int) $this->option("keep")); $toDelete = array_slice($files, $keep); if (empty($toDelete)) { $this->info("Nothing to delete."); return; } foreach ($toDelete as $file) { unlink($file); $this->line("Deleted: " . basename($file)); } $this->info("Deleted " . count($toDelete) . " export(s)."); } }