Re: DirectoryIterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Nathan.

As soon as the PHP documentation does not mention the getRealPath() method, 
I couldn´t realize that this could be done.

-- 
João Cândido de Souza Neto

"Nathan Nobbe" <quickshiftin@xxxxxxxxx> escreveu na mensagem 
news:AANLkTikUQdRHMQM8iH_YL+OVimxLK5pNOQP9HRLn+3VU@xxxxxxxxxxxxxxxxx
2010/8/2 João Cândido de Souza Neto <joao@xxxxxxxxxxxxxxxxxxx>

> 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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux