修复clear指令无法删除多级目录下文件的问题

This commit is contained in:
tale
2017-03-15 10:56:44 +08:00
parent 841edf205d
commit e5cc8308dc

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