SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast teotu's Avatar
    Join Date
    Sep 2004
    Location
    earth
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Directory Functions: Name of current directory

    Hi,

    I'm building a navigation system. I need to know how to match the current directory so that when I make a list of directories, the current directory is not hyperlinked.

    PHP Code:
    <?php
    $files 
    = array();
    $dir opendir('.');
    $mydir dirname($dir);
    while((
    $file readdir($dir)) !== false)
    {
      if(
    $file !== '.' && $file !== '..' && is_dir($file))
      {
        
    $files[] = $file;
      }
    }
    closedir($dir);
    sort($files);
    for(
    $i=0$i<count($files); $i++)
    {
      echo 
    "<li>$files[$i]</li>"  ;
    }
    echo 
    $mydir;
    ?>
    This is the current code I have for testing.

    When I echo the directories, I don't want to hyperlink the current directory.

    Thanks in advance for any help.

    johnny :-)

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    as I can see there is no hyperlink at all
    Your 'current' directory is always '.'

  3. #3
    SitePoint Enthusiast teotu's Avatar
    Join Date
    Sep 2004
    Location
    earth
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by GStyle
    Hi there,

    as I can see there is no hyperlink at all
    Your 'current' directory is always '.'
    Yes, I haven't put the code in for the hyperlink yet.

    By current directory, I meant the directory, not the full path. I found the code that can get me there:

    PHP Code:
    <?php
    // get last directory in current working directory
    $thisdir substr(strrchr(getcwd(), "/"), 1);
    echo 
    $thisdir;
    ?>
    Now I'm having difficulty getting back to my "root" directory--it's driving me nuts:

    PHP Code:
    $dir opendir("."); 
    if my path is /bar/foo/foo/foo

    how do I get back to the directory "bar" from wherever I may be? If "." is the current directory path, how do I specify "bar"?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •