VC++: How to get the time and date of a file?
c++, date, file, size, windows
Solution
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.
Problem
How do I get the file size and date stamp of a file on Windows in C++, given its path?