Delete directory with files in it?

 function deleteDirectory($dirPath) { if (is_dir($dirPath)) { $objects = scandir($dirPath); print_r($objects); foreach ($objects as $object) { if ($object != '.' && $object !=..) { if (filetype($dirPath . DIRECTORY_SEPARATOR . $object) == dir) { deleteDirectory($dirPath . DIRECTORY_SEPARATOR . $object); } else { unlink($dirPath . DIRECTORY_SEPARATOR . $object); } } } reset($objects); rmdir($dirPath); } }