puoi usare la funzione stat()
codice:
#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( "File size : %ld\n", buf.st_size );
printf( "Time modified : %s", ctime( &buf.st_mtime ));
printf( "Time created : %s", ctime( &buf.st_ctime ));
printf( "Time last access : %s", ctime( &buf.st_atime ));
}
}
Nota che su linux se usi ext2/ext3 non puoi avere la data di creazione di un file, in quel caso st_ctime rappresenta la data di ultimo cambiamento "time of last change"
http://www.rt.com/man/stat.2.html
Se il file è già stato aperto con open() o fopen(), puoi usare in quel caso la funzione:
int fstat(int filedes, struct stat *buf);