Assembly Language Help (alang.hlp) (Table of Contents; Topic list)
GetFileTime
 Map                                       Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
;* GetFileTime - Gets date/time for open file specified by handle.
;*
;* Shows:   DOS Function - 57h (Get or Set File Date and Time)
;*          Instructions - shl     shr
;*
;* Params:  Handle - Handle of open file
;*          Sptr - Pointer to 18-byte buffer to receive date/time
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if error
 
GetFileTime PROC USES di,
        Handle:WORD,
        Sptr:PBYTE
 
        mov     ax, 5700h               ; AH = function number
                                        ; AL = get request
        mov     bx, Handle              ; BX = file handle
        int     21h                     ; Get File Date and Time
        mov     ax, 1                   ; Set error code, keep flags
        .IF     !carry?                 ; If not carry, continue
        mov     bx, cx                  ; Else save time in BX
        mov     al, bl                  ; Get low byte of time
        and     al, 00011111y           ; Mask to get 2-second incrs,
        shl     al, 1                   ;   convert to seconds
        push    ax                      ; Save seconds
        mov     cl, 5
        shr     bx, cl                  ; Shift minutes into low byte
        mov     al, bl                  ; Get new low byte
        and     al, 00111111y           ; Mask to get minutes
        push    ax                      ; Save minutes
        mov     cl, 6
        shr     bx, cl                  ; Shift hours into low byte
        push    bx                      ; Save hours
 
        mov     bl, dl                  ; Get low byte of date
        and     bl, 00011111y           ; Mask to get day in BX
        mov     cl, 5
        shr     dx, cl                  ; Shift month into low byte
        mov     al, dl                  ; Get new low byte
        and     al, 00001111y           ; Mask to get month
        mov     cl, 4
        shr     dx, cl                  ; Shift year into low byte
        add     dx, 80                  ; Year is relative to 1980
        push    dx                      ; Save year
        push    bx                      ; Save day
        push    ax                      ; Save month
 
        LoadPtr es, di, Sptr            ; Point ES:DI to 18-byte
        mov     cx, 6                   ;   string
 
        .REPEAT
        pop     ax                      ; Get 6 numbers sequentially in AL
        aam                             ; Convert to unpacked BCD
        xchg    al, ah                  ; Switch bytes for word move
        or      ax, '00'                ; Make ASCII numerals
        stosw                           ; Copy to string
        mov     al, '-'                 ; Separator for date text
        cmp     cl, 4                   ; First 3 iters are for date
        jg      @F                      ; If CX=6 or 5, insert hyphen
        mov     al, ' '                 ; Separator date and time
        je      @F                      ; If CX = 4, insert hyphen
        mov     al, ':'                 ; Separator for time text
        .IF     cl != 1
@@:     stosb                           ; Copy separator to string
        .ENDIF
        .UNTILCXZ
 
        sub     ax, ax                  ; Clear return code
        stosb                           ; Terminate string with null
        .ENDIF                          ;   to make ASCIIZ
        ret
 
GetFileTime ENDP
                                    -♦-