Forum Moderators: coopster

Message Too Old, No Replies

readdir randomly chooses files

Files not listed in order

         

sned

10:11 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



I'm using the usual directory loop script:

while(false!== ($file = readdir($fp))){
echo $file;
}

However, the files are not printed out in order - they come out randomly.

In my case, all files are named the same, except they have a timestamp at the end (webcam images, every 5 minutes). So my listing comes out like: img_20070425_0300.jpg, img_20070425_1324.jpg, img_20070425_0127.jpg, etc.

I can sort the list after I'm done reading it in .. but it's very weird to me why these are coming in randomly (it just started doing this a few days ago, worked fine for months before hand).

Anyone have any ideas on what may be happening? ls shows all the files in their correct order.

Thanks!
-Sned

mcibor

8:24 am on Apr 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Info taken from [php.net...]

Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

Hope this helps
michal

jatar_k

11:58 am on Apr 26, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I see some weird orders when i echo them straight.

just pull them into an array and sort them then output them

sned

4:33 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Yeah, I just pop them into an array and sort, I was just curious. Perhaps it was more of a linux/unix question, since it appears the OS stored them in order, but how do I really tell in which order they are stored.

mcibor

12:35 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Files are stored in a partition table order, on clear disks it's by creation, but later on they fill in the deletion space as well.

Some info on linux filesystem [google.com]

Regards
Michal