$fileInfo = new SplFileInfo('/path/to/file.txt'); $path = $fileInfo->getPath(); echo $path; // outputs "/path/to"
$dirInfo = new SplFileInfo('/path/to/dir'); $path = $dirInfo->getPath(); echo $path; // outputs "/path/to"This example is similar to the first one, but we create a `SplFileInfo` object for a directory instead of a file. The `getPath` function still returns the parent directory's path. Package Library: The `SplFileInfo` class is part of the Standard PHP Library (SPL) package, which is included in PHP by default.