
Get and set file date and time stamps
(Continued from previous message)
Fmt% = GetDateFormat% ' Get national date format
SELECT CASE Fmt%
CASE 0 ' USA
Dt$ = M$ + "-" + D$ + "-" + Y$
CASE 1 ' Europe
Dt$ = D$ + "/" + M$ + "/" + Y$
CASE 2 ' Japan
Dt$ = Y$ + "-" + M$ + "-" + D$
CASE ELSE
END SELECT
H$ = RIGHT$("0" + LTRIM$(RTRIM$(STR$(Hrs%))), 2)
M$ = RIGHT$("0" + LTRIM$(RTRIM$(STR$(Mins%))), 2)
S$ = RIGHT$("0" + LTRIM$(RTRIM$(STR$(Sex%))), 2)
Dt$ = Dt$ + " " + H$ + ":" + M$ + ":" + S$
END IF
REG 2, Handle% ' File handle to BX
REG 1, &H3E00 ' DOS Service 62
CALL INTERRUPT &H21 ' - close the file
END IF
GetFileDate$ = Dt$ ' Return date and time as string
END FUNCTION
' Returns a code indicating the national date format.
'
' Return values: 1 = MM-DD-YY (USA)
' 2 = DD/MM/YY (Europe)
' 3 = YY-MM-DD (Japan)
'
' Depends on COUNTRY = setting in CONFIG.SYS (default = USA)
'
FUNCTION GetDateFormat% ()
B$ = SPACE$(64) ' To hold country information
REG 8, STRSEG(B$) ' DS = segment of buffer
REG 4, STRPTR(B$) ' DX = offset of buffer
REG 1, &H3800 ' DOS Service 56
CALL INTERRUPT &H21 ' - get country information
GetDateFormat% = ASC(B$) ' Date format is first byte
END FUNCTION
' Sets the last-access date and time of the specified file.
'
' Note: FileDate$ must be in one of the following formats:
'
' --123456789012345678--
'
' MM-DD-YY HH:MM:SS (for USA)
' DD/MM/YY HH:MM:SS (for Europe)
' YY-MM-DD HH:MM:SS (for Japan)
'
' (there are two blank spaces between the date and time
'
' If Fmt% is TRUE (non-zero) then the procedure uses the date
' format for the country corresponding to the COUNTRY= setting
' in the computers CONFIG.SYS file (default = USA)
'
' If Fmt% is FALSE (zero) then USA format is used.
'
SUB SetFileDate (FileName$, FileDate$, Fmt%, Done%)
Done% = 0 ' Assume failure
F$ = FileName$ + CHR$(0) ' Make filespec ASCIIZ
REG 8, STRSEG(F$) ' DS = segment of filespec
REG 4, STRPTR(F$) ' DX = offset of filespec
REG 1, &H3D00 ' DOS Service 61
CALL INTERRUPT &H21 ' - open file for reading
Carry% = REG(0) AND 1 ' Check carry flag
IF Carry% = 0 THEN ' If no error occurred..
Handle% = REG(1) ' Get handle from AX
IF Fmt% THEN
Fmt% = GetDateFormat% ' Get national date format
END IF
SELECT CASE Fmt%
CASE 0 ' USA
Day% = VAL(MID$(FileDate$, 4, 2))
Mth% = VAL(LEFT$(FileDate$, 2))
Yr% = VAL(MID$(FileDate$, 7, 2))
CASE 1 ' Europe
Mth% = VAL(MID$(FileDate$, 4, 2))
Day% = VAL(LEFT$(FileDate$, 2))
Yr% = VAL(MID$(FileDate$, 7, 2))
CASE 2 ' Japan
Mth% = VAL(MID$(FileDate$, 4, 2))
Yr% = VAL(LEFT$(FileDate$, 2))
Day% = VAL(MID$(FileDate$, 7, 2))
CASE ELSE
END SELECT
Hrs% = VAL(MID$(FileDate$, 11, 2))
Mins% = VAL(MID$(FileDate$, 14, 2))
Sex% = VAL(MID$(FileDate$, 17, 2)) \ 2
IF Yr% < 80 THEN Yr% = Yr% + 100 ' Remember the 21st Century
FlDate& = Yr% - 80 ' Juggle date
SHIFT LEFT FlDate&, 9 ' into the
SHIFT LEFT Mth%, 5 ' appropriate
FLDate& = FlDate& + Mth% + Day% ' bit-fields
REG 4, FlDate& ' Load result into DX
FlTime& = Hrs% ' Juggle time
SHIFT LEFT FlTime&, 11 ' into the
SHIFT LEFT Mins%, 5 ' appropriate
FlTime& = FlTime& + Mins% + Sex% ' bit-fields
REG 3, FlTime& ' Load result into CX
REG 2, Handle% ' File handle to BX
(Continued to next message)
* 1st 2.00o #323 * I ate a dozen oysters, but only nine of 'em worked.