Merge pull request #566 from hugtale/optimize-console-clear

修复clear指令无法删除多级目录下文件的问题
This commit is contained in:
ThinkPHP
2017-03-14 22:06:25 -05:00
committed by GitHub

View File

@@ -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>");
} }
} }