readdir problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
frederix
Forum Newbie
Posts: 3
Joined: Fri Feb 17, 2006 11:45 am

readdir problem.

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Please explain what you're trying to do and how you define "changing the order filenames are sorted on my linux server"
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: readdir problem.

Post 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 ... ;)
frederix
Forum Newbie
Posts: 3
Joined: Fri Feb 17, 2006 11:45 am

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sort()
natsort()
natcasesort()

may be of interest.

glob() as well.
Post Reply