Is there another ways to get file date stamp?
-
I used the following code to get file date time stamp. CFileFind ff; CFileStatus status; xxxxxx; xxxxxx; CString strFilePath = ff.GetFilePath(); CFile::GetStatus(strFilePath, status); CTime Ftime = status.m_mtime; Ftime is CTime object. But CTime has limit (Year <=2037 or so) is there another ways to get file date time stamp except CFile::GetStatus? Thanks
-
I used the following code to get file date time stamp. CFileFind ff; CFileStatus status; xxxxxx; xxxxxx; CString strFilePath = ff.GetFilePath(); CFile::GetStatus(strFilePath, status); CTime Ftime = status.m_mtime; Ftime is CTime object. But CTime has limit (Year <=2037 or so) is there another ways to get file date time stamp except CFile::GetStatus? Thanks
Have you checked out the Win32 API
GetFileTime
?-------------------------------- "All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
-
Have you checked out the Win32 API
GetFileTime
?-------------------------------- "All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
Thanks. I used GetFileTime. But I got another problem.Following is my code: TCHAR FilePath[MAX_PATH]; TCHAR NewPath[MAX_PATH]; WIN32_FIND_DATA fd; FILETIME mtime, local; SYSTEMTIME st; sprintf(FilePath, "%s\\*.*", strpath); HANDLE hFind = FindFirstFile(FilePath, &fd); if (hFind == INVALID_HANDLE_VALUE) return; do { if (fd.cFileName[0] != '.') { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { sprintf(NewPath, "%s\\%s", strpath, fd.cFileName); Findfiles(NewPath); } else { GetFileTime(hFind, NULL, NULL, &mtime); FileTimeToLocalFileTime( &mtime, &local ); FileTimeToSystemTime(&local, &st); CString time; time.Format("%02d/%02d/%04d", st.wMonth, st.wDay, st.wYear); AfxMessageBox(time); } } } while (FindNextFile(hFind, &fd)); FindClose(hFind); But my file last modofied time is 9/5/2006. The Time always dispalyed as 12/24/18186. what is wrong? Thanks a lot.
-
Thanks. I used GetFileTime. But I got another problem.Following is my code: TCHAR FilePath[MAX_PATH]; TCHAR NewPath[MAX_PATH]; WIN32_FIND_DATA fd; FILETIME mtime, local; SYSTEMTIME st; sprintf(FilePath, "%s\\*.*", strpath); HANDLE hFind = FindFirstFile(FilePath, &fd); if (hFind == INVALID_HANDLE_VALUE) return; do { if (fd.cFileName[0] != '.') { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { sprintf(NewPath, "%s\\%s", strpath, fd.cFileName); Findfiles(NewPath); } else { GetFileTime(hFind, NULL, NULL, &mtime); FileTimeToLocalFileTime( &mtime, &local ); FileTimeToSystemTime(&local, &st); CString time; time.Format("%02d/%02d/%04d", st.wMonth, st.wDay, st.wYear); AfxMessageBox(time); } } } while (FindNextFile(hFind, &fd)); FindClose(hFind); But my file last modofied time is 9/5/2006. The Time always dispalyed as 12/24/18186. what is wrong? Thanks a lot.
The members of the
SYSTEMTIME
structure are of typeWORD
. You need to change your format totime.Format("%02hd/%02hd/%04hd", st.wMonth, st.wDay, st.wYear);
Software Zen:
delete this;