Friday, October 10, 2025
HomeLanguagesPHP | DirectoryIterator isDot() Function

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 is . or .., otherwise FALSE.

Below programs illustrate the DirectoryIterator::isDot() function in PHP:

Program 1:




<?php
  
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
  
// Loop runs for each element of directory
foreach($directory as $dir) {
      
    // Check if not a dot directory
    if (!$dir->isDot()) {
  
        // Display directory element and its permission
        $perms = substr(sprintf('%o', $dir->getPerms()), -4);
        echo $dir->getFilename() . " " 
        . " | Permission: " . $perms . "<br>";
    }
}
  
?>


Output:

applications.html | Permission: 0666
bitnami.css | Permission: 0666
dashboard | Permission: 0777
favicon.ico | Permission: 0666
neveropen.PNG | Permission: 0666
gfg.php | Permission: 0666
img | Permission: 0777
index.php | Permission: 0666
Sublime Text Build 3211 x64 Setup.exe | Permission: 0777
webalizer | Permission: 0777
xampp | Permission: 0777

Program 2:




<?php
  
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
  
// Loop runs while directory is valid
while ($directory->valid()) {
  
    // Check if not a dot directory
    if (!$directory->isDot()) {
        echo $directory->getFilename() . "<br>";
    }
    $directory->next();
}
  
?>


Output:

applications.html
bitnami.css
dashboard
favicon.ico
neveropen.PNG
gfg.php
img
index.php
Sublime Text Build 3211 x64 Setup.exe
webalizer
xampp

Note: The output of this function depends on the content of server folder.

Reference: https://www.php.net/manual/en/directoryiterator.isdot.php

RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6792 POSTS0 COMMENTS