如何获取上次创建的文件名并以“backup”开头?

时间:2014-03-10 02:22:59

标签: posix

如何获取上次创建的文件名并以“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";
}

但是如何在创建时获取元数据?

1 个答案:

答案 0 :(得分:2)

您可以使用stat获取有关文件的大量信息。 stat的输出为struct statstruct 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