用到那个WindowsAPI或者ShellAPI?

解决方案 »

  1.   

    /* 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( "File size     : %ld\n", buf.st_size );
          printf( "Drive         : %c:\n", buf.st_dev + 'A' );
          printf( "Time modified : %s", ctime( &buf.st_atime ) );
       }
    }
    OutputFile size     : 745
    Drive         : C:
    Time modified : Tue May 03 00:00:00 1994
      

  2.   

    使用_stat函数可以获取create modified access的时间。
    Example 
    /* 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>void main( void )
    {
       struct __stat64 buf;
       int result;
       char buffer[] = "A line to output";   /* Get data associated with "stat.c": */
       result = _stat64( "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 ) );
       }
    }
    Output
    File size     : 865
    Drive         : C:
    Time modified : Fri Jan 22 07:44:56 1999
      

  3.   

    // GetLastWriteTime - retrieves the last-write time and converts the
    //                   time to a string
    // Return value - TRUE if successful, FALSE otherwise
    // hFile      - must be a valid file handle
    // lpszString - pointer to buffer to receive stringBOOL GetLastWriteTime(HANDLE hFile, LPSTR lpszString)
    {
        FILETIME ftCreate, ftAccess, ftWrite, ftLocal;
        SYSTEMTIME stCreate;    // Retrieve the file times for the file.
        if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
            return FALSE;    // Convert the last-write time to local time.
        if (!FileTimeToLocalFileTime(&ftWrite, &ftLocal))
            return FALSE;    // Convert the local file time from UTC to system time.
        FileTimeToSystemTime(&ftLocal, &stCreate);    // Build a string showing the date and time.
        wsprintf(lpszString, "%02d/%02d/%d  %02d:%02d",
            stCreate.wDay, stCreate.wMonth, stCreate.wYear,
            stCreate.wHour, stCreate.wMinute);    return TRUE;
    }