VersionPress\Utils\FileSystem::removeContent PHP Method

removeContent() public static method

Removes the content of a directory (not the directory itself). Works recursively.
public static removeContent ( string $path )
$path string Path to a directory.
    public static function removeContent($path)
    {
        if (!is_dir($path)) {
            return;
        }
        $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($iterator as $item) {
            if ($item->isDir() && Strings::endsWith($iterator->key(), ".git")) {
                self::possiblyFixGitPermissions($iterator->key());
            }
        }
        $fs = new \Symfony\Component\Filesystem\Filesystem();
        $fs->remove($iterator);
    }

Usage Example

 protected function setUp()
 {
     parent::setUp();
     FileSystem::removeContent(self::$repositoryPath);
     FileSystem::removeContent(self::$tempPath);
     self::$repository->init();
 }
All Usage Examples Of VersionPress\Utils\FileSystem::removeContent