I'm using this script to see all subfolders and files of subfolders
function readfolder($dir)
{
global $tfile,$tdir;$i=0;$j=0;$myfiles;
$myfiles[][] = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file=readdir($dh)) !== false) {
if (!is_dir($dir."\\".$file))
{
$tfile[$i]=$file;
$i++;
echo $dir."\\".$file." <b>File</b><br>";
}
else {
if (($file != ".") && ($file != "..")) {
$tdir[$j]=$file;
echo $dir."\\".$file." <b>Directory</b><br>";
readfolder($dir."\\".$file);
$j++;
}
}
}
closedir($dh);
}
}
}
readfolder(".");
Can someone tell me how can I use filemtime function (or whatever) so that I can sort subflders and files by modification date?
Have a look at the SPL DirectoryIterator. It's cleaner than what you're currently doing and trivial to make it recursive. It also has a suitable mtime method.