我正在处理一批文件,这些文件包含同一个对象在其生命周期的不同时间的信息,而唯一的排序方式是按创建日期排序。 我曾经使用过这个:
//char* buffer has the name of file
struct stat buf;
FILE *tf;
tf = fopen(buffer,"r");
//check handle
fstat(tf, &buf);
fclose(tf);
pMyObj->lastchanged=buf.st_mtime;
但是它似乎不起作用。我做错了什么?在Linux下获取文件创建日期还有其他更可靠/简单的方法吗?
fstat
不能获取“文件创建”时间戳值,因为许多文件系统不跟踪该数据。你正在使用哪个文件系统? - nobodystat(buffer, &buf)
代替无用的fopen
。 - mpez0