Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetCreationTime, GetLastAccessTime, GetLastWriteTime

Posted on 2003-12-09
4
Medium Priority
?
1,808 Views
Last Modified: 2013-11-20
My code is dying at run-time.  The output displays the filename but nothing else (it bombs after there).  What am I doing wrong?  (Note: I'm looking for the simplest solution that builds upon this little block below, which is merely attempting to display the filename, and related time information).  Thanks.

#include <afx.h>
#include <iostream>
using namespace std;

void main () {
      CFileFind finder;
      CTime creation_time;
      BOOL bWorking = finder.FindFile("C:\\send.bat");
      while (bWorking)
      {
      bWorking = finder.FindNextFile();
      cout << (LPCTSTR) finder.GetFileName() << endl;
        cout << (LPCTSTR) finder.GetCreationTime(creation_time) << endl;
        cout << (LPCTSTR) finder.GetLastAccessTime(creation_time) << endl;
        cout << (LPCTSTR) finder.GetLastWriteTime(creation_time) << endl;
      }
}
0
Comment
Question by:MrSnood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9908601
The GetCreationTime() method returns a bool, and not a CString. You are casting the bool to a LPCTSTR, which of course points to the memory address 0 or 1. That's the reason you are getting a crash.
0
 

Author Comment

by:MrSnood
ID: 9909416
OK, thank you, but how do I cout the stuff I'm actually looking for (the date/times)?  
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 150 total points
ID: 9911377
You need to convert the CTime object to a string first:

finder.GetCreationTime(creation_time);
CString sTime = creation_time.Format( ...your format string ... );
cout << sTime << endl;

Look up the description for CTime::Format() for information about how to format your time string.
0
 
LVL 1

Expert Comment

by:luvjd
ID: 9911462
Hi Snood..
Check this example...

 CFileFind finder;

   BOOL bWorking = finder.FindFile(_T("C:\\*.*"));

   while (bWorking)
   {
      bWorking = finder.FindNextFile();

      _tprintf(_T("%s\n\t"), (LPCTSTR) finder.GetFileName());
      _tprintf(_T("%c"), finder.IsArchived() ? 'A' : 'a');
      _tprintf(_T("%c"), finder.IsCompressed() ? 'C' : 'c');
      _tprintf(_T("%c"), finder.IsHidden() ? 'H' : 'h');
      _tprintf(_T("%c"), finder.IsNormal() ? 'N' : 'n');
      _tprintf(_T("%c"), finder.IsReadOnly() ? 'R' : 'r');
      _tprintf(_T("%c"), finder.IsSystem() ? 'S' : 's');
      _tprintf(_T("%c"), finder.IsTemporary() ? 'T' : 't');

      _tprintf(_T("\t%I64u byte(s)\n"), finder.GetLength());
     
      CTime tempTime;
      CString str;
     
      _tprintf(_T("\tCreated    : "));
      if (finder.GetCreationTime(tempTime))
      {
         str = tempTime.Format(_T("%c"));
         _tprintf(_T("%s\n"), (LPCTSTR) str);
      }
      else
         _tprintf(_T("(unavailable)\n"));

      _tprintf(_T("\tLast Access: "));
      if (finder.GetLastAccessTime(tempTime))
      {
         str = tempTime.Format(_T("%c"));
         _tprintf(_T("%s\n"), (LPCTSTR) str);
      }
      else
         _tprintf(_T("(unavailable)\n"));

      _tprintf(_T("\tLast Write : "));
      if (finder.GetLastWriteTime(tempTime))
      {
         str = tempTime.Format(_T("%c"));
         _tprintf(_T("%s\n"), (LPCTSTR) str);
      }
      else
         _tprintf(_T("(unavailable)\n"));

      _tprintf(_T("\n"));
   }

Luv..
Jd
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question