If you are programming for windows you can use the GetFileTime( ) API to retrieve the Created/LastAccessed/and Last Modified times. These are output in the FILETIME structure, so you will have to use the FileTimeToSystemTime() in order to change the FILETIME structure to a SYSTEMTIME structure.
After that , you can get the current systemtime using the GetSystemTime() and compare this with the times you got for the file.
You can find more in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/time_functions.asp
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Have you been able to get the dates and times? The thing is that SYSTEMDATE is not in the usual "yy mm dd" format. To display this in the way we all understand, you will have to use GetDateFormat and GetTime Format functions. Better is you give us the code up to where you have got the file times and system times. Then it is easier to narrow out the problem.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
int main()
{
char filename[] = "c:\\test.txt";
char timeStr[ 100 ] = "";
struct stat buf;
time_t ltime;
char datebuf [9];
char timebuf [9];
if (!stat(filename, &buf))
{
strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime));
printf("\nLast modified date and time = %s\n", timeStr);
}
else
{
printf("error getting atime\n");
}
_strtime(timebuf);
_strdate(datebuf);
printf("\nThe Current time is %s\n",timebuf);
printf("\nThe Current Date is %s\n",datebuf);
time( <ime );
printf("\nThe Current time is %s\n",ctime( <ime ));
printf("\Diff between current and last modified time ( in seconds ) %f\n", difftime(ltime ,buf.st_mtime ) );
return 0;
}
My Output was
Last modified date and time = 06-04-2005 17:24:12
The Current time is 10:25:53
The Current Date is 06/17/05
The Current time is Fri Jun 17 10:25:53 2005
Diff between current and last modified time ( in seconds ) 6195701.000000
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Use buf.st_atime instead of buf.st_mtime. That is the last accessed time. But keep in mind that since you are accessing that file in your program, the result will be the time you run the program. Even if you right click the file in Windows ( at least in my Windows 2000 OS ) and select properties, you will see that the last accessed time is the time you right clicked the file. I dont know anyway of getting around that. I personally think that the last modified time ( buf.st_mtime) is the one that matters the most in your application. But it can be otherwise. Good luck.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
I think I figured out the problem. It is the File System which makes the stat::a_time come out the same. I found the below in the documentation.
st_atime
Time of last access of file. Valid on NTFS but not on FAT formatted disk drives. Gives the same
Try running this in an NTFS partition, and check the results. Hopefully there will be an improvement in results.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
You will have to use a mechanism of your own, like storing the file name and the dates you require to a file. No built in mechanisms in Windows for it.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115