PHP Recursively File Folder Scan Sorted by Modification Date

匆匆过客 提交于 2019-12-11 01:58:59

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7254748/php-recursively-file-folder-scan-sorted-by-modification-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!