setName('fileconsole') ->addArgument('name', Argument::OPTIONAL, "console name") ->addOption('dir', null, Option::VALUE_REQUIRED, 'directory name') ->setDescription('the fileconsole command'); } protected function execute(Input $input, Output $output) { $name = trim($input->getArgument('name')); $name = $name ?: 'thinkphp'; if ($input->hasOption('dir')) { $dir = str_replace("\\", '/', app()->getRootPath() . $input->getOption('dir')); } else { $dir = str_replace("\\", '/', Config::get('filesystem.disks.public.root')) .'/'; } // 指令输出 $output->writeln('fileconsole :' . $name . "--dir: " . $dir); $this->$name($dir); $output->writeln('..ok'); } /** * 建立文件管理目录索引(递归遍历目录) */ public function scan($dir) { if (is_file($dir)) { $file = new File($dir); FileManager::saveFile($file); } else { $dirs = new DirectoryIterator($dir); foreach ($dirs as $fileInfo) { if($fileInfo->isDot() || $fileInfo->getFilename() == '.gitignore') { continue; } $this->scan($dirs->getPath() . '/' . $fileInfo->getFilename()); } } } /** * 清除无效目录索引 */ public function clear($dir = '') { $list = FileManager::select(); foreach ($list as $value) { $file = app()->getRootPath() . 'public/' . $value->filepath; if (!is_file($file)) { FileManager::destroy($value->fileid); } } } }