php8.5
Home/ Manual/ spl / recursivedirectoryiterator/ RecursiveDirectoryIterator::getSubPathname

RecursiveDirectoryIterator::getSubPathname

PHP function Edit on GitHub ✎

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Get sub path and name

Description

RecursiveDirectoryIterator::getSubPathname(): string

Gets the sub path and filename.

Parameters Parameters

Return Values

The sub path (sub directory) and filename.

Examples

getSubPathname() example

php
      $directory = '/tmp';
      
      $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
      
      foreach ($it as $file) {
          echo 'SubPathName: ' . $it->getSubPathname() . "\n";
          echo 'SubPath:     ' . $it->getSubPath() . "\n\n";
      }
    

The above example will output something similar to:

output
     SubPathName: fruit/apple.xml
     SubPath:     fruit
     
     SubPathName: stuff.xml
     SubPath:     
     
     SubPathName: veggies/carrot.xml
     SubPath:     veggies
    

See Also

  • RecursiveDirectoryIterator::getSubPath
  • RecursiveDirectoryIterator::key

Source: reference/spl/recursivedirectoryiterator/getsubpathname.xml · from the official PHP manual (php/doc-en)