Page 1 of 1

readdir problem.

Posted: Fri Feb 17, 2006 11:47 am
by frederix
This question is more operationg system specific than php but the problem starts in php.
According to php.net in function readdir description: "The filenames are returned in the order in which they are stored by the filesystem".

Many people developed some code to sort these returned names and i think they are ok.

For specific problems on my code i cant use the solutions provied.

So, i am thinking on changing the order filenames are "sorted" on my linux server.

Any idea on how to view this order and edit it?

Thanx a lot.

Posted: Fri Feb 17, 2006 12:46 pm
by feyd
Please explain what you're trying to do and how you define "changing the order filenames are sorted on my linux server"

Re: readdir problem.

Posted: Fri Feb 17, 2006 12:52 pm
by Chris Corbyn
frederix wrote:This question is more operationg system specific than php but the problem starts in php.
According to php.net in function readdir description: "The filenames are returned in the order in which they are stored by the filesystem".

Many people developed some code to sort these returned names and i think they are ok.

For specific problems on my code i cant use the solutions provied.

So, i am thinking on changing the order filenames are "sorted" on my linux server.

Any idea on how to view this order and edit it?

Thanx a lot.
You can't really change that. It's filesystem dependent. Not exactly something you can modify without root acess... and even then, probably without changing the kernel/fs source.

If the scripts available don't do what you need you can always write your own. the basic concept would be to get all filenames into an array and there's a whole host of array functions to help you from there on ... ;)

Posted: Fri Feb 17, 2006 12:53 pm
by frederix
Thanx for the reply.

I have folder with 4 subfloders names "1", "2", "3", "4".

When i call them with readdir the output order is not 1,2,3,4.
The order in my example on is "3,1,2,4".
I need an order for this output(1,2,3,4) and i want to change in the server and not in the code if possible.

Maybe there are "commands" to change the storage information of files.
readdir uses this storage information for output order.

Thanx again and i hope this clear things.

Posted: Fri Feb 17, 2006 1:00 pm
by Chris Corbyn
frederix wrote:Thanx for the reply.

I have folder with 4 subfloders names "1", "2", "3", "4".

When i call them with readdir the output order is not 1,2,3,4.
The order in my example on is "3,1,2,4".
I need an order for this output(1,2,3,4) and i want to change in the server and not in the code if possible.

Maybe there are "commands" to change the storage information of files.
readdir uses this storage information for output order.

Thanx again and i hope this clear things.
There are no commands you as a "user" can run to change the filesystem. I've never known any modern filesystem to do that though... the only time I see that bevahiour is with numbers without leading zeros.

Either way, a simple sort() would do that for you :)

Posted: Fri Feb 17, 2006 1:00 pm
by feyd
sort()
natsort()
natcasesort()

may be of interest.

glob() as well.