php-windows | 2001051

Re: [PHP-WIN] HELP: Print directory structure. From: Daniel Beulshausen (daniel <email protected>)
Date: 05/15/01

At 16:10 15.05.2001 +0200, Alessio Bernesco Lāvore wrote:
>Could someone help me, please?
>
>I have to build a recursive function that print to video all the directories
>(and sub-directories and so on...) names presents in a specified
>sub-directory on the server.
>
>I can't handle that function, please, i'm in panic...

you can use something like the following

<?php
  function dir_to_array($dir = "./") {
    $realpath = realpath($dir);
    if(!($dir =  <email protected>($realpath))) {
      return false;
    }

    $retval = array();
    $ignore = array("." => true, ".." => true);

    while($raw = $dir->read()) {
      if($ignore[$raw]) {
        continue;
      }

      $entry = $realpath . "\\" . $raw;
      if(!is_dir($entry)) {
        $readable = is_readable($entry) ? 1 : 0;
        $writeable = is_writeable($entry) ? 2 : 0;
        $retval[$raw] = $readable | $writeable;
      } else {
        $retval[$raw] = dir_to_array($entry);
      }
    }

    return $retval;
  }

  $array = dir_to_array("../");
  print_r($array);
?>

daniel

/*--
daniel beulshausen - daniel <email protected>
using php on windows? http://www.php4win.de

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-windows-unsubscribe <email protected>
For additional commands, e-mail: php-windows-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>