Syntax:public FilesystemIterator::__ construct (string $path, int $flags)
Parameters:This function takes two parameters as above and described below: - $path: this parameter contains the path to the file system element.
- $flags:this parameter contains a flag that provides the influence and behavior of some methods.
Returned value:this function does not return any value.The following programs illustrate the FilesystemIterator::__ construct() function in PHP:Program 1:
// Create a new file system iterator
$fileItr
=
new
FilesystemIterator (dirname (
__ FILE__
));
// the loop starts for each element of the file system
foreach
(
$fileItr
as
$file
) {
// Show file name
echo
$file
-> getFilename().
"
"
;
}
?>
Output:applications.html bitnami.css dashboard favicon.ico engineer.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
Program 2:
// Create a new file system iterator
$fileItr
=
new
FilesystemIterator (dirname (
__ FILE__
));
// Loop starts while the file iterator is active
while
(
$fileItr
-> valid()) {
// Check catalog files
if
(
$fileItr
-> isDir()) {
// Show filename
echo
$fileItr
-> getFilename().
"
"
;
}
// Move to next item
$fileItr
-> next();
}
?>
Output:dashboard img webalizer xampp
Note . The output of this function depends on the contents of the server folder.Link: https : //www.php.net/manual/en/filesystemiterator.construct.php