How to read the date & time of 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?...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    51

    How to read the date & time of a file?

    how to read created / modified / accessed date n time for a file?

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    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

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    _stat() (CRT)
    or
    GetFileAttributesEx() (Win32 API)

    gg

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    51
    thanks
    but i get 4 error and 2 warning when compling this sample code provided by MSDN in VC++ 6
    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(13) : error C2079: 'buf' uses undefined struct '__stat64'
    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....

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    Unfortunately, the examples aren't always correct (for 6.0).
    Code:
    "struct __stat64" -> "struct _stati64"
    "_stat64()" -> "_stati64()"
    "_ctime64()" -> "ctime()"
    gg

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    51
    thanks!!! ^_^ and i already figured out how to compare which file is newer...!! yippi!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Replies: 3
    Last Post: 11-20-2008, 11:31 AM
  3. Date and time stamp in printing to a file
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-24-2007, 02:59 AM
  4. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 03:33 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21