Gets the date and time a file was last written, using system call 0x57.
#include <dos.h>
#include <errno.h>
unsigned _dos_getftime( int handle, unsigned *date, unsigned *time );
handle | Target file | |
date | Date-return buffer | |
time | Time-return buffer |
The _dos_getftime routine uses system call 0x57 to get the date and time that the specified file was last written. The file must have been opened with a call to _dos_open or _dos_creat prior to calling _dos_getftime. The date and time are returned in the words pointed to by date and time. The values appear in the DOS date and time format:
Time Bits | Meaning |
0–4 | Number of 2-second increments (0–29) |
5–10 | Minutes (0–59) |
11–15 | Hours (0–23) |
Date Bits | Meaning |
0–4 | Day (1–31) |
5–8 | Month (1–12) |
9–15 | Year (1980–2099) |
If successful, the function returns 0. Otherwise, it returns the DOS error code and sets errno to EBADF, indicating that an invalid file handle was passed.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* DGFTIME.C: This program displays and modifies the date and time
* fields of a file.
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
void main( void )
{
/* FEDC BA98 7654 3210 */
unsigned new_date = 0x26cf; /* 0010 0110 1100 1111 12/15/99 */
unsigned new_time = 0x48e0; /* 0100 1000 1110 0000 9:07 AM */
unsigned old_date, old_time;
int fh;
/* Open file with _dos_open function */
if( _dos_open( "dgftime.obj", _O_RDONLY, &fh ) != 0 )
exit( 1 );
/* Get file date and time */
_dos_getftime( fh, &old_date, &old_time );
printf( "Old date field: 0x%.4x\n", old_date );
printf( "Old time field: 0x%.4x\n", old_time );
system( "dir dgftime.obj" );
/* Modify file date and time */
if( !_dos_setftime( fh, new_date, new_time ) )
{
_dos_getftime( fh, &new_date, &new_time );
printf( "New date field: 0x%.4x\n", new_date );
printf( "New time field: 0x%.4x\n", new_time );
system( "dir dgftime.obj" );
/* Restore date and time */
_dos_setftime( fh, old_date, old_time );
}
_dos_close( fh );
}
Old date field: 0x274f
Old time field: 0x94bb
Volume in drive C is ZEPPELIN
Directory of C:\LIBREF
DGFTIME OBJ 3923 6-15-99 6:37p
1 File(s) 13676544 bytes free
New date field: 0x26cf
New time field: 0x48e0
Volume in drive C is ZEPPELIN
Directory of C:\LIBREF
DGFTIME OBJ 3923 12-15-99 9:07a
1 File(s) 13676544 bytes free