|
|
@@ -654,4 +654,34 @@ EOF';
|
|
|
}, "");
|
|
|
}
|
|
|
|
|
|
+ static function deleteWholeDirectory($dir, $returnFiles = false, $doDelete = true) {
|
|
|
+ if (!is_dir($dir)) throw new Exception("{$dir} must be a directory");
|
|
|
+ $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
|
|
|
+ $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
|
|
+
|
|
|
+ if ($doDelete) {
|
|
|
+ $rmdir = 'rmdir';
|
|
|
+ $unlink = 'unlink';
|
|
|
+ } else {
|
|
|
+ $rmdir = 'is_string';
|
|
|
+ $unlink = 'is_string';
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($returnFiles) {
|
|
|
+ $return = [];
|
|
|
+ foreach ($files as $file) {
|
|
|
+ if ($file->isDir()) $return['dirs'][$file->getRealPath()] = @$rmdir($file->getRealPath());
|
|
|
+ else $return['files'][$file->getRealPath()] = @$unlink($file->getRealPath());
|
|
|
+ }
|
|
|
+ $return['dirs'][$dir] = @$rmdir($dir);
|
|
|
+ return $return;
|
|
|
+ } else {
|
|
|
+ foreach ($files as $file) {
|
|
|
+ if ($file->isDir()) @$rmdir($file->getRealPath());
|
|
|
+ else @$unlink($file->getRealPath());
|
|
|
+ }
|
|
|
+ @$rmdir($dir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|