mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
Merge pull request #566 from hugtale/optimize-console-clear
修复clear指令无法删除多级目录下文件的问题
This commit is contained in:
@@ -28,17 +28,27 @@ class Clear extends Command
|
|||||||
|
|
||||||
protected function execute(Input $input, Output $output)
|
protected function execute(Input $input, Output $output)
|
||||||
{
|
{
|
||||||
$path = $input->getOption('path') ?: RUNTIME_PATH;
|
$path = $input->getOption('path') ?: RUNTIME_PATH;
|
||||||
|
|
||||||
|
if (is_dir($path)) {
|
||||||
|
$this->clearPath($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln("<info>Clear Successed</info>");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function clearPath($path)
|
||||||
|
{
|
||||||
|
$path = realpath($path) . DS;
|
||||||
$files = scandir($path);
|
$files = scandir($path);
|
||||||
if ($files) {
|
if ($files) {
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if ('.' != $file && '..' != $file && is_dir($path . $file)) {
|
if ('.' != $file && '..' != $file && is_dir($path . $file)) {
|
||||||
array_map('unlink', glob($path . $file . '/*.*'));
|
$this->clearPath($path . $file);
|
||||||
} elseif ('.gitignore' != $file && is_file($path . $file)) {
|
} elseif ('.gitignore' != $file && is_file($path . $file)) {
|
||||||
unlink($path . $file);
|
unlink($path . $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$output->writeln("<info>Clear Successed</info>");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user