如何获取上次创建的文件名并以“backup”开头? 我列出了像
这样的目录DIR *dir;
struct dirent *ent;
if ((dir = opendir (directory.c_str())) != NULL) {
while ((ent = readdir (dir)) != NULL) {
string name(ent->d_name);
}
closedir (dir);
} else {
/* could not open directory */
perror ("");
return "EXIT_FAILURE";
}
但是如何在创建时获取元数据?
答案 0 :(得分:2)
您可以使用stat
获取有关文件的大量信息。 stat
的输出为struct stat
。 struct stat
包含以下成员数据:
struct timespec st_atim; /* time of last access */
struct timespec st_mtim; /* time of last modification */
struct timespec st_ctim; /* time of last status change */
这足以满足您的需求吗?
有关stat
的更多信息,请参阅its man page。