Re: DirectoryIterator
| From: | Nathan Nobbe | Date: | Mon, 02 Aug 2010 18:52:25 +0000 |
| Subject: | Re: DirectoryIterator | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307285@lists.php.net to get a copy of this message | ||
2010/8/2 João Cândido de Souza Neto <joao@consultorweb.cnt.br>
> Is there a way of getting the symbolic link's target when using
> DirectoryIterator?
>
as DirectoryIterator traverses the contents of a directory, the current()
method will return an SplFileInfo instance.
Using the SplFileInfo, you can determine if the entry is a link and if so,
dereference it
http://www.php.net/manual/en/splfileinfo.islink.php
(note: $oFile is internally being populated via $oIt->current())
<?php
$oIt = new DirectoryIterator('./');
foreach($oIt as $oFile)
if($oFile->isLink())
{
echo 'link found' . PHP_EOL;
echo 'link points to: ' . $oFile->getRealPath() . PHP_EOL;
}
?>
-nathan