获取文件夹中最近更新的文件的filemtime [英] Get filemtime for most recently updated file in folder
本文介绍了获取文件夹中最近更新的文件的filemtime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含4个文件的文件夹,我想提取最近一个的上次修改时间(可能并不总是相同的).有什么好办法吗?
I have a folder with 4 files in it and I'd like to pull the last modified time of the most recent one (which may not always be the same one). Is there a good way to do that?
推荐答案
使用 DirectoryIterator 查找文件,然后简单地比较它们的修改时间.应该这样做:
Use a DirectoryIterator to find the files and then simply compare their modified times. This oughta do it:
$iterator = new DirectoryIterator('path/to/dir');
$mtime = -1;
$file;
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
if ($fileinfo->getMTime() > $mtime) {
$file = $fileinfo->getFilename();
$mtime = $fileinfo->getMTime();
}
}
}
这篇关于获取文件夹中最近更新的文件的filemtime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文