我想檢索文件上的最後寫入日期。我已經寫了此代碼,但它返回我在52428像值「年」的所有時間C++系統時間返回相同的錯誤值
int LastErrorCode;
LPCSTR Path = "C:/Users/Username/Desktop/Picture.PNG";
WIN32_FIND_DATA Information;
if(!FindFirstFile(Path, &Information))
{
int LastErrorCode = GetLastError();
cout << "FIND FIRST FILE FAILED" << endl;
cout << LastErrorCode << endl;
}
SYSTEMTIME MyTime;
FILETIME MyFileTime = Information.ftLastWriteTime;
if(!FileTimeToSystemTime(&MyFileTime, &MyTime))
{
LastErrorCode = GetLastError();
cout << "FILE TIME TO SYSTEM TIME FAILED" << endl;
cout << LastErrorCode << endl;
}
cout << MyTime.wYear << endl;
嘿。 FileTimeToSystemTime失敗,我得到錯誤代碼87,意思是「參數不正確。」。我不知道什麼是錯的。 *我已更新回答中的代碼 – Janman
@Janman:我添加了更多信息。我懷疑你對FindFirstFile的調用失敗(結果不是「布爾」類型)。 –