Professional Web Applications Themes

directory list - strange behaviuor - PHP Development

Hello, I've written a simple script to list directory content and all subdirectories content (only xml files). The script has all rights to read an execute directories. The problem is that this function does not perform content listing of all subdirectories, it does listing only for first subdirectory in alfabethical order. Any clue? This is the function: function chklimit($dirName) { static $ret; $dir = opendir($dirName); chdir($dirName) or die("Cannot change to this directory"); while ($file = readdir($dir)) { if (is_dir($file) && $file != "." && $file != "..") { chklimit($dirName."/".$file); } $ext = explode(".", $file); if ($file != "." && $file ...

  1. #1

    Default directory list - strange behaviuor

    Hello,

    I've written a simple script to list directory content and
    all subdirectories content (only xml files). The script has
    all rights to read an execute directories. The problem is
    that this function does not perform content listing of all
    subdirectories, it does listing only for first subdirectory
    in alfabethical order.

    Any clue?

    This is the function:

    function chklimit($dirName) {
    static $ret;
    $dir = opendir($dirName);
    chdir($dirName) or die("Cannot change to this directory");
    while ($file = readdir($dir)) {
    if (is_dir($file) && $file != "." && $file != "..") {
    chklimit($dirName."/".$file);
    }
    $ext = explode(".", $file);
    if ($file != "." && $file != ".." && $ext[1] == 'xml')
    $ret .= $dirName."/".$file."<br>";
    }
    return $ret;
    }

    Thanks in advance
    Kleist Guest

  2. #2

    Default Re: directory list - strange behaviuor

     


    Change this condition for
    while (FALSE !== $file = readdir($dir))

    still doesn`t work properly
    Kleist Guest

  3. #3

    Default Re: directory list - strange behaviuor

    Kleist wrote:
     
    <snip> 

    Yup - you're not capturing the return value of the recursed function. Should
    be
    $ret.= chklimit($dirName."/".$file);

    Also you'll be fscked if you have a filename with more than one '.' in it,
    or a dirname with a '.' in it.

    C.

    Colin Guest

  4. #4

    Default Re: directory list - strange behaviuor

    Kleist wrote: 

    Ok, solved ;)

    one has test absolute path in is_dir()
    Kleist Guest

  5. #5

    Default Re: directory list - strange behaviuor

    Colin McKinnon wrote:
     

    $ret declared as STATIC and it does well
     

    Thanks for attract my attantion on that, that must be
    rearranged.

    Thanks for reply
    Kleist Guest

Similar Threads

  1. strange behaviuor when assigning string
    By andy in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: November 11th, 05:38 AM
  2. ITemplate strange behaviuor
    By tremway@yahoo.com in forum ASP.NET Building Controls
    Replies: 1
    Last Post: August 29th, 09:38 PM
  3. How to list a directory
    By Rolf in forum PHP Development
    Replies: 2
    Last Post: January 16th, 04:13 PM
  4. Getting a list of the files in a directory
    By Revision17 in forum Ruby
    Replies: 6
    Last Post: October 2nd, 03:43 PM
  5. Strange Directory ~/vw
    By Sally Shears in forum Mac Applications & Software
    Replies: 4
    Last Post: July 2nd, 04:59 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139