By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

readdir is not reading the full directory, why?

P: n/a
Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.
If I use the readdir test script on an older machine everything works
fine.

My server has Suse 9.1 installed with all php modules that come with
it.

Has anyone had this problem before? I could not fine anything similar
on goggle.

Oliver
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Oliver wrote:
Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.
So it is not random.
If I use the readdir test script on an older machine everything works
fine.


What is the loop inside which is the readdir() call?
Specifically the test condition?
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #2

P: n/a

"Oliver" <o.****@reading.ac.uk> wrote in message
news:f5**************************@posting.google.c om...
Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.
If I use the readdir test script on an older machine everything works
fine.

My server has Suse 9.1 installed with all php modules that come with
it.

Has anyone had this problem before? I could not fine anything similar
on goggle.

Oliver


Post the damned script already.

Incidentally, when I get random crap like that, it's usually because I
re-used the loop variable by mistake. Have a look.

Garp
Jul 17 '05 #3

P: n/a


Pedro Graca wrote:
Oliver wrote:

Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.
So it is not random.

It is random for each directory, but there it is same as lang as I don't
change or add a file/folder.

If I use the readdir test script on an older machine everything works
fine.


What is the loop inside which is the readdir() call?
Specifically the test condition?

Thats my readdir test script:

<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>

Oliver
Jul 17 '05 #4

P: n/a
Oliver Otto wrote:


Pedro Graca wrote:
Oliver wrote:

Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.

So it is not random.

It is random for each directory, but there it is same as lang as I don't
change or add a file/folder.

If I use the readdir test script on an older machine everything works
fine.

What is the loop inside which is the readdir() call?
Specifically the test condition?

Thats my readdir test script:

<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>

Oliver


Looks like you are missing the @opendir

if ($handle = @opendir('./'))
// ^^^ this is missing in your script.
{
while ($file = readdir($handle)
echo "$file\n";
}
closedir($handle);
Jul 17 '05 #5

P: n/a
On Mon, 28 Jun 2004 20:19:42 GMT, Michael Austin <ma*****@firstdbasource.com>
wrote:
Thats my readdir test script:

<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>
Looks like you are missing the @opendir

if ($handle = @opendir('./'))
// ^^^ this is missing in your script.


Why would you want to SUPPRESS errors when there is something unexpected going
on?
{
while ($file = readdir($handle)
echo "$file\n";
}
closedir($handle);


--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #6

P: n/a
On Mon, 28 Jun 2004 20:33:51 +0100, Oliver Otto <Ol*********@gmx.de> wrote:
It is random for each directory, but there it is same as lang as I don't
change or add a file/folder.
If I use the readdir test script on an older machine everything works
fine.

What is the loop inside which is the readdir() call?
Specifically the test condition?

Thats my readdir test script:

<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>


OK, that's your script, which looks like a plain and correct example of using
opendir/readdir. Now post:

(1) The output of the script above.
(2) The output of another program, e.g. 'ls -l', on that directory to
demonstrate that the output is different to that expected.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #7

P: n/a
In article <y3*****************@newssvr22.news.prodigy.com> , Michael Austin wrote:
Oliver Otto wrote:


Pedro Graca wrote:
Oliver wrote:
Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.

So it is not random.

It is random for each directory, but there it is same as lang as I don't
change or add a file/folder.


If I use the readdir test script on an older machine everything works
fine.

What is the loop inside which is the readdir() call?
Specifically the test condition?

Thats my readdir test script:

<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>

Oliver


Looks like you are missing the @opendir

if ($handle = @opendir('./'))

The @ will only hide errors. So in this case i would certainly not
recommend to use it. Below is the function i use to obtain the files in
a directory. It can be easily expanded to support recursion too.

function listdir($directory) {
$results = array();
if ($handler = @opendir($directory)) {
while ($file = readdir($handler)) {
if (!is_dir($directory.'/'.$file)) {
$results[] = $file;
}
}
closedir($handler);
}
return $results;
}

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #8

P: n/a

"Oliver" <o.****@reading.ac.uk> wrote in message
news:f5**************************@posting.google.c om...
Hi,

I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.
If I use the readdir test script on an older machine everything works
fine.

My server has Suse 9.1 installed with all php modules that come with
it.

Has anyone had this problem before? I could not fine anything similar
on goggle.

Oliver


My advice: use glob().
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.