downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DirectoryIterator::getPathname> <DirectoryIterator::getOwner
[edit] Last updated: Fri, 25 May 2012

view this page in

DirectoryIterator::getPath

(PHP 5)

DirectoryIterator::getPath現在の Iterator アイテムのパスをファイル名抜きで返す

説明

public string DirectoryIterator::getPath ( void )

現在の DirectoryIterator アイテムのパスを取得します。

パラメータ

この関数にはパラメータはありません。

返り値

ファイルへのパスを返します。ファイル名や最後のスラッシュは省略します。

例1 DirectoryIterator::getPath() の例

<?php
$iterator 
= new DirectoryIterator(dirname(__FILE__));
echo 
$iterator->getPath();
?>

上の例の出力は、 たとえば以下のようになります。

/home/examples/public_html

参考



add a note add a note User Contributed Notes DirectoryIterator::getPath
xcojack at gmail dot com 04-Apr-2012 06:19
If you wish to get a part of path you can use function like this:

<?php
/**
 * Return a part of path by depth
 *
 * @param $path string
 * @param $depth int
 * @return mixed string on success, false on failure
 */
function getPartPath($path = '', $depth = 0) {
   
$pathArray = array();
   
$pathArray = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));  
    if(
$depth < 0)
       
$depth = count($pathArray)+$depth;

    if(!isset(
$pathArray[$depth]))
        return
false;
    return
$pathArray[$depth];
}
?>

usage:

<?php
$a
= "/var/www/foo/trunk/bar/tools/php/simplelocal";

var_dump(getPartPath($a, -2)); // returns php
var_dump(getPartPath($a, 0)); // returns var
var_dump(getPartPath($a, -1)); // returns simplelocal
?>

etc...

Regards.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites