VC ++:如何获取文件的时间和日期? [英] VC++: How to get the time and date of a file?
问题描述
如何获取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屋!