b9
asked on
Getting and comparing file dates/times
Needed: NT C source to get file (c:\aaa\bbb\c.ext) date/time and see if it is over xyz number of hours old since last read/write.
Lookup _stat in MSVC help, example:
/* STAT.C: This program uses the _stat function to
* report information about the file named STAT.C.
*/
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
void main( void )
{
struct _stat buf;
int result;
char buffer[] = "A line to output";
/* Get data associated with "stat.c": */
result = _stat( "stat.c", &buf );
/* Check if statistics are valid: */
if( result != 0 )
perror( "Problem getting information" );
else
{
/* Output some of the statistics: */
printf( "Time modified : %s", ctime( &buf.st_atime ) );
}
}
/* STAT.C: This program uses the _stat function to
* report information about the file named STAT.C.
*/
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
void main( void )
{
struct _stat buf;
int result;
char buffer[] = "A line to output";
/* Get data associated with "stat.c": */
result = _stat( "stat.c", &buf );
/* Check if statistics are valid: */
if( result != 0 )
perror( "Problem getting information" );
else
{
/* Output some of the statistics: */
printf( "Time modified : %s", ctime( &buf.st_atime ) );
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent. Thank you for the quick response time as well. SystemTimeToVariantTime is undocumented?
It's documented in the copy of MSDN that I have.
B ekiM
B ekiM
GetStatus(LPCTSTR lpszFileName, CFileStatus& rStatus );
The CFileStatus class has the following member variables:
-CTime m_ctime The date and time the file was created.
-CTime m_mtime The date and time the file was last modified.
-CTime m_atime The date and time the file was accessed for read
-LONG m_size The logical size of the file in bytes
-BYTE m_attribute The attribute byte of the file.
-char m_szFullName[_MAX_PATH] The absolute filenam
I'm not sure about the true C source for it though? sorry.