PHP | DirectoryIterator isDir() Function
The DirectoryIterator::isDir() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item is a directory or not.
Syntax:
bool DirectoryIterator::isDir( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns TRUE if the directory exist, FALSE otherwise.
Below programs illustrate the DirectoryIterator::isDir() function in PHP:
Program 1:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isDir()) {
$file = $directory ->current();
echo $file ->getFilename() . " | Size: "
. $directory ->getSize() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
. | Size: 4096
.. | Size: 12288
dashboard | Size: 4096
img | Size: 0
webalizer | Size: 0
xampp | Size: 0
Program 2:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isDir()) {
$file = $directory ->current();
echo $file ->getFilename() . " | MTime: "
. $directory ->getMTime() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
. | MTime: 1574654324
.. | MTime: 1574540515
dashboard | MTime: 1574350724
img | MTime: 1574350724
webalizer | MTime: 1574350718
xampp | MTime: 1574350724
Note: The output of this function depends on the content of server folder.
Last Updated :
07 Mar, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...