Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Complete directory search script help

    Hi,

    It's me again with my wonderful ideas

    I am trying to make a script that echoes something like this:
    Code:
    folder
    another
    yes\fold
    yes\fold\anotherone
    yes\folderagain
    justfolder
    etc
    heehoo\heh
    So it basically displayes EVERY folder listed each by one line.
    Here's a sample script I have made so far:
    PHP Code:
    function scan_directory($dir)
     {
      
    $a scandir($dir);
      
    $b = array();
      foreach (
    $a as $key)
       {
        if (
    $key != "." && $key != ".." && !preg_match("/\\./",$key))
         
    $b[] = $key// Getting all FOLDERS, not files, to single array
       
    }
      
    $c = array();
      foreach (
    $b as $key)
       {
        
    $c[] = scan_directory("$dir/$key");
       }
      return (
    $c);
     }
    $dir scan_directory("kcms");
    print_r($dir); 
    But obviously it's not working corretcly...
    Here's another one I have tried:
    PHP Code:
    function scan_directory($dir)
     {
      
    $a scandir($dir);
      
    $b = array();
      foreach (
    $a as $key)
       {
        if (
    $key != "." && $key != ".." && !preg_match("/\\./",$key))
         
    $b[] = $key// Getting all FOLDERS, not files, to single array
       
    }
      
    $c "";
      foreach (
    $b as $key)
       {
        
    $c .= scan_directory("$dir/$key");
       }
      return (
    $c);
     }
    $dir scan_directory("kcms");
    echo(
    $dir); 
    But this one outputs nothing!

    Do anyone have any ideas? I'm doing this script for my own personal use, this script would save A LOT time if I got it working.

    Thanks for your time,
    Kai
    PHP 5 & MySQL 5 (Y)

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    this will do the job for you ...

    PHP Code:
       echo '<h1>Index</h1>';
       echo 
    '<ul>';
       echo 
    '<li><a href="/"> Parent Directory</a></li>';

       
    $dir scandir('.');
       
    $files count$dir );
       for ( 
    $i 0$i $files$i++ )
       {
           if ( 
    is_file($dir[$i]) )
               echo 
    "<li><a href=\"$dir[$i]\">$dir[$i]</a></li><br>";

           if ( 
    is_dir($dir[$i]) )
               echo 
    "<li><a href=\"$dir[$i]\"/>$dir[$i]/</a></li><br>";
       }

       echo 
    '</ul>'

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks, but that does not do the job

    It only shows the one directory. I need a script that shows all folders from ALL folders. This means COMPLETE directory search, not just one folder... :/
    PHP 5 & MySQL 5 (Y)

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    I missed that bit sorry ..

    anyway the code is all here :
    http://uk.php.net/scandir

    the examples are worth working through, there are some examples doing it recursively like you need ..

    good luck

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    There was an example posted in the post a php forum:
    http://www.codingforums.com/showthread.php?t=71882

    Good luck;

  • #6
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks for that link mate, needed!
    PHP 5 & MySQL 5 (Y)


  •  

    Posting Permissions

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