28 lines
546 B
PHP
28 lines
546 B
PHP
|
<?php
|
||
|
|
||
|
/**
|
||
|
* Namespace for Folder related classes and functions.
|
||
|
* @package NAE\Functions\Folder
|
||
|
*/
|
||
|
namespace NAE\Functions\Folder;
|
||
|
|
||
|
/**
|
||
|
* Recursive removes a directory and its contents
|
||
|
* @param string $dir Target directory to be removed
|
||
|
*/
|
||
|
function rrmdir(string $dir) {
|
||
|
|
||
|
if (is_dir($dir)) {
|
||
|
$files = scandir($dir);
|
||
|
foreach ($files as $file)
|
||
|
if ($file != "." && $file != "..") rrmdir("$dir/$file");
|
||
|
rmdir($dir);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
if (file_exists($dir)) {
|
||
|
unlink($dir);
|
||
|
}
|
||
|
|
||
|
}
|