This is a discussion on "Directory of files not in alphabetical order" within the PHP Forum section. This forum, and the thread "Directory of files not in alphabetical order are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Directory of files not in alphabetical order
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Using the following loop to run through a fileset on my server and present a set of links to those files for download.
Thanks, Rob. |
|
|
|
#2
|
||||
|
||||
|
Re: Directory of files not in alphabetical order
Not knowing PHP too well I think there will be a better way, but I personally would the filenames into an array and then sort it alphabetically.... then just loop through the array to pull out the filenames.
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#3
|
|||
|
|||
|
Re: Directory of files not in alphabetical order
Thanks Rob.
I had though that but i wondered if there was something blindingly obvious that is houd do to get the effect. Will prepare an array versio njust in case there is no other way. Ta, Rob. |
|
#4
|
|||
|
|||
|
Re: Directory of files not in alphabetical order
Yay!
http://ca.php.net/manual/en/function.asort.php *runs into a wall* You can sort an array alphabetically with asort($array) |
|
#5
|
|||
|
|||
|
Re: Directory of files not in alphabetical order
PHP's readdir returns the names of the file system objects in a directory in the order that they're actually stored in the index tables on the disc.
Sorting can be a resource hungry operation and you don't always need to get the names back in any particular order. For example, if you're traversing a whole directory tree and looking for just half a dozen files, there's no point in sorting all the names in every directory you go through and it would slow things right down (ever noticed how an ls or dir - which are the OS commands that DO produce sorted lists - pause noticably on very large directories?). So - use readdir to traverse your directory/ies, store any file system objects that match your requirements into an array, and sort just that smaller list of wanted objects ...., yes, Phoenix, asort is one of the possible sort functions. As an aside - do you want to sort your listing with all the upper case names ahead of the lower case names, or with them all folded together, or even by file size? Using readdir and something like sort, asort, ksort or natsort you have all the flexibility you could wish for. |
|
#6
|
|||
|
|||
|
Re: Directory of files not in alphabetical order
So my code shoudl change to not display the items straight away but to put them in an array.
Then asort... Then walkthrough the array and dsiplay all values using the fomat i've used already. Cool and thanks. |
![]() |
| Tags |
| directory, files, alphabetical, order |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Display text files in order | cedric813 | PHP Forum | 2 | Oct 22nd, 2007 13:48 |
| Order By | Maverick25r | PHP Forum | 2 | Jun 28th, 2007 13:29 |
| help with order for needed | bruno89 | Web Page Design | 21 | Oct 1st, 2006 04:38 |
| Putting files in a directory | franknu | PHP Forum | 1 | Jun 27th, 2006 09:53 |
| Tab Order | aje | Web Page Design | 2 | May 13th, 2006 14:49 |