_dos_setftime

Description

Sets the date and time for a file, using system call 0x57.

#include <dos.h>

unsigned _dos_setftime( int handle, unsigned date, unsigned time );

handle Target file  
date Date of last write  
time Time of last write  

Remarks

The _dos_setftime routine uses system call 0x57 to set the date and time at which the file identified by handle was last written to. These values appear in the DOS date and time format, described in the following lists:

Time Bits Meaning

0–4 Number of two-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 since 1980 (for example, 1999 is stored as 9)

Return Value

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.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

_dos_getftime, _fstat, _stat

Example

/* 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 );

}

Output

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