VC ++:如何获取文件的时间和日期? [英] VC++: How to get the time and date of a file?

查看:167
本文介绍了VC ++:如何获取文件的时间和日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Windows上C ++文件的文件大小和日期戳记?您可以使用 FindFirstFile()来同时获取它们,而不必打开它(这是 GetFileSize() GetInformationByHandle())。这是一个有点费力,所以有点包装是有帮助的

  bool get_file_information(LPCTSTR路径,WIN32_FIND_DATA *数据)
{
HANDLE h = FindFirstFile(path,& data);
if(INVALID_HANDLE_VALUE!= h){
return false;
} else {
FindClose(h);
返回true;






然后文件大小在 nFileSizeHigh nFileSizeLow WIN32_FIND_DATA ,时间戳可用于 ftCreationTime ftLastAccessTime ftLastWriteTime 成员。


How do I get the file size and date stamp of a file on Windows in C++, given its path?

解决方案

You can use FindFirstFile() to get them both at once, without having to open it (which is required by GetFileSize() and GetInformationByHandle()). It's a bit laborious, however, so a little wrapper is helpful

bool get_file_information(LPCTSTR path, WIN32_FIND_DATA* data)
{
  HANDLE h = FindFirstFile(path, &data);
  if(INVALID_HANDLE_VALUE != h) {
    return false;
  } else {
    FindClose(h);
    return true;
  }
}

Then the file size is available in the nFileSizeHigh and nFileSizeLow members of WIN32_FIND_DATA, and the timestamps are available in the ftCreationTime, ftLastAccessTime and ftLastWriteTime members.

这篇关于VC ++:如何获取文件的时间和日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆