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)); }
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)); }
|