Skip to content

Instantly share code, notes, and snippets.

@pepijnolivier
pepijnolivier / recursivelyPruneDirectory.php
Created March 8, 2023 09:43
PHP: Recursively delete old files and folder in a given directory
/**
* @param $folderName | The full directory name
* @param $maxAge | Max Age in seconds. 172800 = 2 days.
*/
private function recursivelyPruneDirectory($folderName, $maxAge = 60)
{
$items = array_diff(scandir($folderName), ['.','..']);
foreach ($items as $fileOrFolder) {