c - 如何以编程方式设置文件的修改时间?

标签 c windows file

如何在 Windows 中以编程方式设置文件的修改时间?

最佳答案

发件人:http://rosettacode.org/wiki/File/Modification_Time#C

#include <time.h>
#include <utime.h>
#include <sys/stat.h>

const char *filename = "input.txt";

int main() {
  struct stat foo;
  time_t mtime;
  struct utimbuf new_times;

  stat(filename, &foo);
  mtime = foo.st_mtime; /* seconds since the epoch */

  new_times.actime = foo.st_atime; /* keep atime unchanged */
  new_times.modtime = time(NULL);    /* set mtime to current time */
  utime(filename, &new_times);

  return 0;
}

关于c - 如何以编程方式设置文件的修改时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2185338/

相关文章:

windows - 如何以管理员身份在 rake 任务中运行 shell 命令?

c++ - 如何在 MS Windows 中使用 C++ 将快捷方式发送到另一个应用程序?

c++ - 从文本文件读取到代表月份的二维数组

java - 如何正确地单元测试 "abstracted"文件处理?

c++ - 如何将文件读入元组 vector ?

c++ - 进程间通信:传递C样式结构与C++对象

c - 定位头文件的规则

c - 从C中的数组中删除元素

c - "lvalue required in asm statement"错误

c++ - 将 Qt 与自定义 MinGW 结合使用