fipamo/app/Helpers/DirectoryHelpers.php
ro bc7b1fe7ec
FEATURE: Restore to default
plugged in a new feature that will allow the site to be reset to its
default state, clearing out all content and configurations to start
fresh
2024-07-02 17:09:27 -06:00

43 lines
1 KiB
PHP

<?php
function delete_directory($dirPath, $catch = true)
{
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 {
if ($catch) {
throw new Exception(__FUNCTION__ . '(dirPath): dirPath is not a directory!');
} else {
//just keep going
}
}
}
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);
}
}