解决方案是将最后访问时间存储在全局变量中,并使用过滤器选择最新文件
scandir():
int cmp_mtime( const struct dirent** lentry, const struct dirent** rentry ):
- 统计信息
(*lentry)->d_name
(由路径扩展,但这仅是详细信息) ltime = statbuf.st_mtime;
- 统计信息
(*rentry)->d_name
(由路径扩展,但这仅是详细信息) rtime = statbuf.st_mtime;
if ( ltime < rtime ) return -1;
else if ( ltime > rtime ) return 1;
return 0;
int selector( const struct dirent* entry ):
- 统计信息
entry->d_name
(由路径扩展,但这仅是详细信息) - 如果不是正常文件则返回0
- 如果
stat.st_mtime > lastseen
然后返回1,否则返回0
主要:
- 初始化全局时间变量
lastseen
scandir( directory, &entries, selector, cmp_mtime );
- 处理条目列表
- lastseen:= m列表中最后一个条目的时间



