wishthis/includes/functions/deleteDirectory.php

25 lines
493 B
PHP
Raw Normal View History

2022-01-21 13:49:26 +00:00
<?php
/**
* Delete a directory with all of its contents.
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
function delete_directory(string $directoryToDelete)
{
foreach (scandir($directoryToDelete) as $filename) {
$filepath = $directoryToDelete . '/' . $filename;
if (is_file($filepath)) {
unlink($filepath);
}
if (is_dir($filepath)) {
delete_directory($filepath);
}
}
unlink($directoryToDelete);
}