PasteAll.org
ResultType Line::FileGetTime(char *aFilespec, char aWhichTime)
{
g_ErrorLevel->Assign(ERRORLEVEL_ERROR); // Set default.
OUTPUT_VAR->Assign(); // Init to be blank, in case of failure.

if (!aFilespec || !*aFilespec)
return OK; // Let ErrorLevel indicate an error, since this is probably not what the user intended.

// Don't use CreateFile() & FileGetSize() size they will fail to work on a file that's in use.
// Research indicates that this method has no disadvantages compared to the other method.
WIN32_FIND_DATA found_file;
HANDLE file_search = FindFirstFile(aFilespec, &found_file);
if (file_search == INVALID_HANDLE_VALUE)
return OK; // Let ErrorLevel tell the story.
FindClose(file_search);

FILETIME local_file_time;
switch (toupper(aWhichTime))
{
case 'C': // File's creation time.
FileTimeToLocalFileTime(&found_file.ftCreationTime, &local_file_time);
break;
case 'A': // File's last access time.
FileTimeToLocalFileTime(&found_file.ftLastAccessTime, &local_file_time);
break;
default: // 'M', unspecified, or some other value. Use the file's modification time.
FileTimeToLocalFileTime(&found_file.ftLastWriteTime, &local_file_time);
}

g_ErrorLevel->Assign(ERRORLEVEL_NONE); // Indicate success.
char local_file_time_string[128];
return OUTPUT_VAR->Assign(FileTimeToYYYYMMDD(local_file_time_string, local_file_time));
}
  1. ResultType Line::FileGetTime(char *aFilespec, char aWhichTime)
  2. {
  3.         g_ErrorLevel->Assign(ERRORLEVEL_ERROR); // Set default.
  4.         OUTPUT_VAR->Assign(); // Init to be blank, in case of failure.
  5.  
  6.         if (!aFilespec || !*aFilespec)
  7.                 return OK;  // Let ErrorLevel indicate an error, since this is probably not what the user intended.
  8.  
  9.         // Don't use CreateFile() & FileGetSize() size they will fail to work on a file that's in use.
  10.         // Research indicates that this method has no disadvantages compared to the other method.
  11.         WIN32_FIND_DATA found_file;
  12.         HANDLE file_search = FindFirstFile(aFilespec, &found_file);
  13.         if (file_search == INVALID_HANDLE_VALUE)
  14.                 return OK;  // Let ErrorLevel tell the story.
  15.         FindClose(file_search);
  16.  
  17.         FILETIME local_file_time;
  18.         switch (toupper(aWhichTime))
  19.         {
  20.         case 'C': // File's creation time.
  21.                 FileTimeToLocalFileTime(&found_file.ftCreationTime, &local_file_time);
  22.                 break;
  23.         case 'A': // File's last access time.
  24.                 FileTimeToLocalFileTime(&found_file.ftLastAccessTime, &local_file_time);
  25.                 break;
  26.         default:  // 'M', unspecified, or some other value.  Use the file's modification time.
  27.                 FileTimeToLocalFileTime(&found_file.ftLastWriteTime, &local_file_time);
  28.         }
  29.  
  30.     g_ErrorLevel->Assign(ERRORLEVEL_NONE);  // Indicate success.
  31.         char local_file_time_string[128];
  32.         return OUTPUT_VAR->Assign(FileTimeToYYYYMMDD(local_file_time_string, local_file_time));
  33. }
go to heaven