Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is there another ways to get file date stamp?

Is there another ways to get file date stamp?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pcname
    wrote on last edited by
    #1

    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

    Richard Andrew x64R 1 Reply Last reply
    0
    • P pcname

      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

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        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

        P Offline
        P Offline
        pcname
        wrote on last edited by
        #3

        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.

        G 1 Reply Last reply
        0
        • P pcname

          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.

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #4

          The members of the SYSTEMTIME structure are of type WORD. You need to change your format to

          time.Format("%02hd/%02hd/%04hd", st.wMonth, st.wDay, st.wYear);


          Software Zen: delete this;

          Fold With Us![^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups