Saturday, November 16, 2024
Google search engine
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

Recent Comments