Task/File/FolderBrowserTask.php
public function execute(ProcessState $state)
    {
        $options = $this->getOptions($state);
        if (null === $this->files) {
            $finder = new Finder();
            $finder->files();
            if ($options['name_pattern']) {
                $finder->name($options['name_pattern']);
            }
            $this->files = $finder->in($options['folder_path'])->sortByName()->getIterator();
            $this->files->rewind();
        }

        if (!$this->files->valid()) {
            $this->logger->log($options['empty_log_level'], "No item found in path {$options['folder_path']}");
            $state->setSkipped(true);
            $state->setErrorOutput($options['folder_path']);
            $this->files = null;

            return;
        }
        /** @var SplFileInfo $fileInfo */
        $fileInfo = $this->files->current();
        $filePath = $fileInfo->getPathname();
        $state->addErrorContextValue('current_file_path', $filePath);
        $state->setOutput($filePath);
    }
public function execute(ProcessState $state)
    {
        $options = $this->getOptions($state);
        if (null === $this->files) {
            $finder = new Finder();
            $finder->files();
            if ($options['name_pattern']) {
                $finder->name($options['name_pattern']);
            }
            $this->files = $finder->in($options['folder_path'])->sortByName()->getIterator();
            $this->files->rewind();
        }

        if (!$this->files->valid()) {
            $this->logger->log($options['empty_log_level'], "No item found in path {$options['folder_path']}");
            $state->setSkipped(true);
            $state->setErrorOutput($options['folder_path']);
            $this->files = null;

            return;
        }
        /** @var SplFileInfo $fileInfo */
        $fileInfo = $this->files->current();
        $filePath = $fileInfo->getPathname();
        $state->addErrorContextValue('current_file_path', $filePath);
        $state->setOutput($filePath);
    }
@param ProcessState $state

@throws \LogicException
@throws \InvalidArgumentException
@throws \Symfony\Component\OptionsResolver\Exception\ExceptionInterface