User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » PHP: dir/subdir folders reverse first, files alpha Page [1]  
quagmire02
All American
44225 Posts
user info
edit post

before folks here started publishing a lot of content as pages, they produced PDFs, word documents, etc and as a result, we have a boatload of archived files on the web that probably no one ever looks at

most are in folders, sorted by date...so the structure is like:


[root]
file1.pdf
file2.doc
file3.xlsx
20130101
- file4.pdf
- file5.doc
- file6.xlsx
20130102
- file7.pdf
- file8.doc
- file9.xlsx
all i want to do is create a series of unordered lists that link to the files, titled by the date of the folder in descending order (most recent date is first), the files in the folder sorted alphabetically, and those files in the root in their own category...something like:

20130102
- link to file7.pdf
- link to file8.doc
- link to file9.xlsx
20130101
- link to file4.pdf
- link to file5.doc
- link to file6.xlsx
unsorted files in the root
- link to file1.pdf
- link to file2.doc
- link to file3.xlsx
i figured the easiest thing to do is do a recursive directory read and store it as an array:
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
but now i have to play with the array and i can't (quickly) think of a way to keep me from wasting a lot of time on this

anyone have a function that already does this? or am i missing something extremely obvious? am i making out the array sorting to be more tedious than it is?

5/16/2013 1:35:44 PM

BigMan157
no u
103354 Posts
user info
edit post

some combo of krsort and uasort

5/16/2013 6:30:20 PM

moron
All American
34142 Posts
user info
edit post

How does recursiveiteratoriterator store directories?

Seems like it would be easier to have an array of array lists with the array lists storing the files in the directory, and the array being keyed by directory.

Then you just sort the array, then spit out the array lists sorted.

5/16/2013 8:25:55 PM

quagmire02
All American
44225 Posts
user info
edit post

just ended up using glob...wasn't as involved as i thought it would be (though still more than i was hoping)

5/17/2013 10:51:24 AM

 Message Boards » Tech Talk » PHP: dir/subdir folders reverse first, files alpha Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.