how to read created / modified / accessed date n time for a file?
This is a discussion on How to read the date & time of a file? within the C Programming forums, part of the General Programming Boards category; how to read created / modified / accessed date n time for a file?...
how to read created / modified / accessed date n time for a file?
os specific, in linux look at stat(). not sure about windows.
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
_stat() (CRT)
or
GetFileAttributesEx() (Win32 API)
gg
thanks
but i get 4 error and 2 warning when compling this sample code provided by MSDN in VC++ 6
d:\my documents\my c source\time.c(13) : error C2079: 'buf' uses undefined struct '__stat64'Code:// crt_stat.c /* This program uses the _stat64 function to * report information about the file named stat.c. */ #include <time.h> #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> int main( void ) { struct __stat64 buf; int result; /* Get data associated with "crt_stat.c": */ result = _stat64( "crt_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( "Drive : %c:\n", buf.st_dev + 'A' ); printf( "Time modified : %s", _ctime64( &buf.st_mtime ) ); } }
d:\my documents\my c source\time.c(17) : warning C4013: '_stat64' undefined; assuming extern returning int
d:\my documents\my c source\time.c(25) : error C2224: left of '.st_size' must have struct/union type
d:\my documents\my c source\time.c(26) : error C2224: left of '.st_dev' must have struct/union type
d:\my documents\my c source\time.c(27) : warning C4013: '_ctime64' undefined; assuming extern returning int
d:\my documents\my c source\time.c(27) : error C2224: left of '.st_mtime' must have struct/union type
Error executing cl.exe.
2) If the program above works ... how to compare which file is newer.. since the Time modified is in string format....
Unfortunately, the examples aren't always correct (for 6.0).
ggCode:"struct __stat64" -> "struct _stati64" "_stat64()" -> "_stati64()" "_ctime64()" -> "ctime()"
thanks!!! ^_^ and i already figured out how to compare which file is newer...!! yippi!!