mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
Update functions_cli.php
This commit is contained in:
parent
a30b199b30
commit
f9f761277c
1 changed files with 17 additions and 7 deletions
|
@ -15,13 +15,18 @@ if (!defined('BB_ROOT')) {
|
||||||
* Remove target file
|
* Remove target file
|
||||||
*
|
*
|
||||||
* @param string $file Path to file
|
* @param string $file Path to file
|
||||||
|
* @param bool $withoutOutput Hide output
|
||||||
*/
|
*/
|
||||||
function removeFile(string $file): void
|
function removeFile(string $file, bool $withoutOutput = false): void
|
||||||
{
|
{
|
||||||
if (unlink($file)) {
|
if (unlink($file)) {
|
||||||
echo "- File removed: $file" . PHP_EOL;
|
if ($withoutOutput === false) {
|
||||||
|
echo "- File removed: $file" . PHP_EOL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "- File cannot be removed: $file" . PHP_EOL;
|
if ($withoutOutput === false) {
|
||||||
|
echo "- File cannot be removed: $file" . PHP_EOL;
|
||||||
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +35,9 @@ function removeFile(string $file): void
|
||||||
* Remove folder (recursively)
|
* Remove folder (recursively)
|
||||||
*
|
*
|
||||||
* @param string $dir Path to folder
|
* @param string $dir Path to folder
|
||||||
|
* @param bool $withoutOutput Hide output
|
||||||
*/
|
*/
|
||||||
function removeDir(string $dir): void
|
function removeDir(string $dir, bool $withoutOutput = false): void
|
||||||
{
|
{
|
||||||
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
||||||
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
|
@ -40,14 +46,18 @@ function removeDir(string $dir): void
|
||||||
if ($file->isDir()) {
|
if ($file->isDir()) {
|
||||||
removeDir($file->getPathname());
|
removeDir($file->getPathname());
|
||||||
} else {
|
} else {
|
||||||
removeFile($file->getPathname());
|
removeFile($file->getPathname(), $withoutOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rmdir($dir)) {
|
if (rmdir($dir)) {
|
||||||
echo "- Folder removed: $dir" . PHP_EOL;
|
if ($withoutOutput === false) {
|
||||||
|
echo "- Folder removed: $dir" . PHP_EOL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "- Folder cannot be removed: $dir" . PHP_EOL;
|
if ($withoutOutput === false) {
|
||||||
|
echo "- Folder cannot be removed: $dir" . PHP_EOL;
|
||||||
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue