Solved

GetCreationTime, GetLastAccessTime, GetLastWriteTime

Posted on 2003-12-09
4
1,749 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 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 77
ASCII Non-Printable characters/codes and their HTML equivalents 6 159
lucky13 challenge 11 168
Fibonacci challenge 11 141
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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