PHP | DirectoryIterator isDir() Function Last Updated : 07 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 <?php // Create a directory Iterator $directory = new DirectoryIterator(dirname(__FILE__)); // Loop runs while directory is valid while ($directory->valid()) { // Check for directory element if ($directory->isDir()) { $file = $directory->current(); // Display the filename and its size echo $file->getFilename() . " | Size: " . $directory->getSize() . "<br>"; } // Move to the next element $directory->next(); } ?> Output: . | Size: 4096 .. | Size: 12288 dashboard | Size: 4096 img | Size: 0 webalizer | Size: 0 xampp | Size: 0 Program 2: php <?php // Create a directory Iterator $directory = new DirectoryIterator(dirname(__FILE__)); // Loop runs while directory is valid while ($directory->valid()) { // Check for directory element if ($directory->isDir()) { $file = $directory->current(); // Display file name and last modified time echo $file->getFilename() . " | MTime: " . $directory->getMTime() . "<br>"; } // Move to the next element $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. Comment More infoAdvertise with us Next Article PHP | DirectoryIterator isDir() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators Similar Reads PHP | DirectoryIterator isDot() Function The DirectoryIterator::isDot() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item is '.' or '..' Syntax: bool DirectoryIterator::isDot( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE if the entry 2 min read PHP | DirectoryIterator isFile() Function The DirectoryIterator::isFile() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item is a regular file or not. Syntax: bool DirectoryIterator::isFile( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE 1 min read PHP | DirectoryIterator isLink() Function The DirectoryIterator::isLink() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item is a symbolic link or not. Syntax: bool DirectoryIterator::isLink( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRU 1 min read PHP | DirectoryIterator key() Function The DirectoryIterator::key() function is an inbuilt function in PHP which is used to return the key for the current DirectoryIterator item. Syntax: string DirectoryIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the key for the curr 2 min read PHP | DirectoryIterator getSize() Function The DirectoryIterator::getSize() function is an inbuilt function in PHP which is used to returns the size of the current DirectoryIterator item. Syntax: int DirectoryIterator::getSize( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the size of th 2 min read Like