PHP | DirectoryIterator getPathname() Function
Last Updated :
07 Mar, 2024
The DirectoryIterator::getPathname() function is an inbuilt function in PHP which is used to return the path and file name of the current DirectoryIterator item.
Syntax:
string DirectoryIterator::getPathname( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the path and file name of current file. The directories do not contain the trailing slash.
Below programs illustrate the DirectoryIterator::getPathname() function in PHP:
Program 1:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
foreach ( $directory as $dir ) {
echo $directory ->getPathname() . "<br>" ;
}
?>
|
Output:
C:\xampp\htdocs\.
C:\xampp\htdocs\..
C:\xampp\htdocs\applications.html
C:\xampp\htdocs\bitnami.css
C:\xampp\htdocs\dashboard
C:\xampp\htdocs\favicon.ico
C:\xampp\htdocs\geeks.PNG
C:\xampp\htdocs\gfg.php
C:\xampp\htdocs\img
C:\xampp\htdocs\index.php
C:\xampp\htdocs\webalizer
C:\xampp\htdocs\xampp
Program 2:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isDir()) {
echo $directory ->getPathname() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
C:\xampp\htdocs\.
C:\xampp\htdocs\..
C:\xampp\htdocs\dashboard
C:\xampp\htdocs\img
C:\xampp\htdocs\webalizer
C:\xampp\htdocs\xampp
Note: The output of this function depends on the content of server folder.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...