PHP | FilesystemIterator __construct() Function
Last Updated :
26 Nov, 2019
Improve
The FilesystemIterator::__construct() function is an inbuilt function in PHP which is used to construct a new filesystem iterator.
Syntax:
php
Output:
php
Output:
public FilesystemIterator::__construct( string $path, int $flags )Parameters: This function accepts two parameters as mentioned above and described below:
- $path: This parameter holds the path of the filesystem item.
- $flags: This parameter holds the flag which provides the affect and behavior of some methods.
<?php
// Create new file system iterator
$fileItr = new FilesystemIterator(dirname(__FILE__));
// Loop runs for each element of filesystem
foreach ($fileItr as $file) {
// Display the filename
echo $file->getFilename() . "<br>";
}
?>
applications.html bitnami.css dashboard favicon.ico geeks.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xamppProgram 2:
<?php
// Create new file system iterator
$fileItr = new FilesystemIterator(dirname(__FILE__));
// Loop runs while file iterator is valid
while ($fileItr->valid()) {
// Check for directory files
if ($fileItr->isDir()) {
// Display the file name
echo $fileItr->getFilename() . "<br>";
}
// Move to the next element
$fileItr->next();
}
?>
dashboard img webalizer xamppNote: The output of this function depends on the content of server folder. Reference: https://www.php.net/manual/en/filesystemiterator.construct.php