2024-07-01 03:50:27 +02:00
|
|
|
<?php
|
|
|
|
|
2024-07-03 01:09:27 +02:00
|
|
|
function delete_directory($dirPath, $catch = true)
|
2024-07-01 03:50:27 +02:00
|
|
|
{
|
|
|
|
if (is_dir($dirPath)) {
|
|
|
|
$objects = new DirectoryIterator($dirPath);
|
|
|
|
foreach ($objects as $object) {
|
|
|
|
if (!$object->isDot()) {
|
|
|
|
if ($object->isDir()) {
|
|
|
|
delete_directory($object->getPathname());
|
|
|
|
} else {
|
|
|
|
unlink($object->getPathname());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir($dirPath);
|
|
|
|
} else {
|
2024-07-03 01:09:27 +02:00
|
|
|
if ($catch) {
|
|
|
|
throw new Exception(__FUNCTION__ . '(dirPath): dirPath is not a directory!');
|
|
|
|
} else {
|
|
|
|
//just keep going
|
|
|
|
}
|
2024-07-01 03:50:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy_directory($src, $dst)
|
|
|
|
{
|
|
|
|
if (file_exists($dst)) {
|
|
|
|
rrmdir($dst);
|
|
|
|
}
|
|
|
|
if (is_dir($src)) {
|
|
|
|
mkdir($dst);
|
|
|
|
$files = scandir($src);
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file != "." && $file != "..") {
|
|
|
|
copy_directory("$src/$file", "$dst/$file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif (file_exists($src)) {
|
|
|
|
copy($src, $dst);
|
|
|
|
}
|
|
|
|
}
|