php8.5
Home/ Manual/ spl / filesystemiterator/ FilesystemIterator::current

FilesystemIterator::current

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

The current file

Description

FilesystemIterator::current(): string|SplFileInfo|FilesystemIterator

Get file information of the current element.

Parameters Parameters

Return Values

The filename, file information, or $this depending on the set flags. See the FilesystemIterator constants.

Examples

FilesystemIterator::current example

This example will list the contents of the directory containing the script.

php
<?php
$iterator = new FilesystemIterator(__DIR__, FilesystemIterator::CURRENT_AS_PATHNAME);
foreach ($iterator as $fileinfo) {
    echo $iterator->current() . "\n";
}
?>

Similar

output
/www/examples/.
/www/examples/..
/www/examples/apple.jpg
/www/examples/banana.jpg
/www/examples/example.php

See Also

Source: reference/spl/filesystemiterator/current.xml · from the official PHP manual (php/doc-en)