Home > Archive > PHP Language > August 2005 > directory list - strange behaviuor
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
directory list - strange behaviuor
|
|
| Kleist 2005-08-11, 3:59 am |
| 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 2005-08-11, 3:59 am |
|
> while ($file = readdir($dir)) {
Change this condition for
while (FALSE !== $file = readdir($dir))
still doesn`t work properly
| |
| Kleist 2005-08-11, 3:59 am |
| Kleist wrote:
> 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
Ok, solved ;)
one has test absolute path in is_dir()
| |
| Colin McKinnon 2005-08-11, 3:59 am |
| Kleist wrote:
> 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.
>
<snip>
>
> 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;
> }
>
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.
| |
| Kleist 2005-08-11, 3:59 am |
| Colin McKinnon wrote:
>
> Yup - you're not capturing the return value of the recursed function. Should
> be
> $ret.= chklimit($dirName."/".$file);
>
$ret declared as STATIC and it does well
> Also you'll be fscked if you have a filename with more than one '.' in it,
> or a dirname with a '.' in it.
Thanks for attract my attantion on that, that must be
rearranged.
Thanks for reply
|
|
|
|
|