Julie-San Posted April 19, 2009 Share Posted April 19, 2009 Hi guys. I am very new to php and would like to know how to use scandir function to obtain a list of folders only, then output (via echo) these folders sorted by creation date or if possible last modified date. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/154710-solved-using-scandir-to-get-list-of-directories-with-extra-info/ Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 scandir is_dir Quote Link to comment https://forums.phpfreaks.com/topic/154710-solved-using-scandir-to-get-list-of-directories-with-extra-info/#findComment-813525 Share on other sites More sharing options...
Julie-San Posted April 19, 2009 Author Share Posted April 19, 2009 Thanks, but it is mainly the sorting part which I am unsure about! Quote Link to comment https://forums.phpfreaks.com/topic/154710-solved-using-scandir-to-get-list-of-directories-with-extra-info/#findComment-813528 Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 k well then you would actually need Ingredients: 1 opendir 1 while loop 1 readdir 1 if condition 1 is_dir 1 filemtime 1 closedir 1 asort or arsort Instructions: assign opendir to a variable. create a loop with the while, with readdir as the condition. inside the loop, check if the current file is a directory, with is_dir. If it is, create an array called $dirs with the file name as the key, and the last modified time as the value (using filemtime). after the loop, close the dir with closedir, and use asort for ascending sort by last modified time, or arsort for descending ordering. Quote Link to comment https://forums.phpfreaks.com/topic/154710-solved-using-scandir-to-get-list-of-directories-with-extra-info/#findComment-813538 Share on other sites More sharing options...
Julie-San Posted April 19, 2009 Author Share Posted April 19, 2009 Thanks! You've been a great help Quote Link to comment https://forums.phpfreaks.com/topic/154710-solved-using-scandir-to-get-list-of-directories-with-extra-info/#findComment-813598 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.