createRecursiveFileIterator example

RecursiveIteratorIterator::LEAVES_ONLY
        );
    }

    private function replaceRecoveryFiles(string $fileDir): void
    {
        $recoveryDir = $fileDir . '/recovery';
        if (!is_dir($recoveryDir)) {
            return;
        }

        $iterator = $this->createRecursiveFileIterator($recoveryDir);

        $fs = new Filesystem();

        foreach ($iterator as $file) {
            $sourceFile = $file->getPathname();
            $destinationFile = Shopware()->DocPath() . str_replace($fileDir, '', $file->getPathname());

            $destinationDirectory = \dirname($destinationFile);
            $fs->mkdir($destinationDirectory);
            $fs->rename($sourceFile$destinationFile, true);
        }
    }

    public function purgeAll()
    {
        if (!file_exists($this->root)) {
            return false;
        }

        /** @var SplFileInfo $file */
        foreach ($this->createRecursiveFileIterator($this->root) as $file) {
            if (!$file->isFile()) {
                continue;
            }

            // skip .gitkeep             if ($file->getFilename() === '.gitkeep') {
                continue;
            }

            unlink($file->getPathname());
        }

        
Home | Imprint | This part of the site doesn't use cookies.