473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

readdir is not reading the full directory, why?

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
8 4601
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

"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


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
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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
5017
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.