告诉上次在 C 中访问文件的时间 [英] Telling when file was last accessed in C
问题描述
在 Windows 中,如果您转到文件的属性,它会在上次修改时间的正下方显示上次访问时间.当我复制它时,这会改变.
In Windows, if you go to a file's properties it shows the last access time right under the time last modified. This changes when I copy it.
我如何在 C 中查看它?
How do I view this in C?
推荐答案
获取最后修改时间戳的可移植方式是使用 fstat 或 stat.如果您想使用仅限 Windows 的路线(通过直接调用 Windows API),请参阅@xxbbcc 的回答.
The portable way of getting the last modified timestamp is by using fstat or stat. If you want to go the Windows-only route (by directly calling a Windows API), see @xxbbcc's answer.
请参阅 如何在 C++ 中获取文件的大小? 对于使用 stat/fstat 的一小段示例代码 - 仅针对您的目的进行的更改是您需要阅读 time_t st_mtime
字段.
See How can I get a file's size in C++? for a short piece of sample code that uses stat/fstat - only change for your purpose is that you'll want to read the time_t st_mtime
field.
这篇关于告诉上次在 C 中访问文件的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!