Thread: interpreting time fields in a structure

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    interpreting time fields in a structure

    Anyone know how to interpret the time fields in the _finddata_t structure. I searched msdn but it curiously wasnt any help. Im using Visual C++
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Found this just by typing _finddata_t into the search box for MSDN. It relates to information returned from the _findfirst/_findnext set of functions.
    Code:
    The _finddata_t structure includes the following elements:
    
    unsigned attrib
    
        File attribute
    
    time_t time_create
    
        Time of file creation ( –1L for FAT file systems)
    
    time_t time_access
    
        Time of last file access (–1L for FAT file systems)
    
    time_t time_write
    
        Time of last write to file
    
    _fsize_t size
    
        Length of file in bytes
    
    char name[_MAX_FNAME]
    
        Null-terminated name of matched file/directory, without the path
    
    In file systems that do not support the creation and last access
    times of a file, such as the FAT system, the time_create and 
    time_access fields are always –1L.
    
    _MAX_FNAME is defined in STDLIB.H as 256 bytes.
    
    Example
    
    /* FFIND.C: This program uses the 32-bit _find functions to print
     * a list of all files (and their attributes) with a .C extension
     * in the current directory.
     */
    
    #include <stdio.h>
    #include <io.h>
    #include <time.h>
    
    void main( void )
    {
        struct _finddata_t c_file;
        long hFile;
    
        /* Find first .c file in current directory */
        if( (hFile = _findfirst( "*.c", &c_file )) == -1L )
           printf( "No *.c files in current directory!\n" );
       else
       {
                printf( "Listing of .c files\n\n" );
                printf( "\nRDO HID SYS ARC  FILE         DATE %25c SIZE\n", ' ' );
                printf( "--- --- --- ---  ----         ---- %25c ----\n", ' ' );
                printf( ( c_file.attrib & _A_RDONLY ) ? " Y  " : " N  " );
                printf( ( c_file.attrib & _A_SYSTEM ) ? " Y  " : " N  " );
                printf( ( c_file.attrib & _A_HIDDEN ) ? " Y  " : " N  " );
                printf( ( c_file.attrib & _A_ARCH )   ? " Y  " : " N  " );
                printf( " %-12s %.24s  %9ld\n",
                   c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
    
                /* Find the rest of the .c files */
                while( _findnext( hFile, &c_file ) == 0 )
                {
                    printf( ( c_file.attrib & _A_RDONLY ) ? " Y  " : " N  " );
                    printf( ( c_file.attrib & _A_SYSTEM ) ? " Y  " : " N  " );
                    printf( ( c_file.attrib & _A_HIDDEN ) ? " Y  " : " N  " );
                    printf( ( c_file.attrib & _A_ARCH )   ? " Y  " : " N  " );
                    printf( " %-12s %.24s  %9ld\n",
                       c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
                }
    
           _findclose( hFile );
       }
    }
    
    
    Output
    
    Listing of .c files
    
    RDO HID SYS ARC  FILE         DATE                           SIZE
    --- --- --- ---  ----         ----                           ----
     N   N   N   Y   CWAIT.C      Tue Jun 01 04:07:26 1993       1611
     N   N   N   Y   SPRINTF.C    Thu May 27 04:59:18 1993        617
     N   N   N   Y   CABS.C       Thu May 27 04:58:46 1993        359
     N   N   N   Y   BEGTHRD.C    Tue Jun 01 04:00:48 1993       3726
    Looks to me like you need to use the ctime functions on that info.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    rofl, I didnt scroll down to the bottom the page Thanks.
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time synchronization problem
    By freeindy in forum C Programming
    Replies: 1
    Last Post: 04-19-2007, 06:25 AM
  2. bit fields in a structure
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 04-18-2007, 12:10 PM
  3. Cycling through the fields in a structure
    By clancyPC in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 12:27 PM
  4. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM