Microsoft KB Archive/38492

= FILEATTR Gets MS-DOS File Handle to Get File Date/Time Stamp =

Article ID: 38492

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q38492



SUMMARY
When you open a file with the OPEN statement in a compiled Basic program, the file number that you give is not the MS-DOS file handle. Instead, the file number acts as a pointer into an internal table that Basic uses to hold the file handles. You can use the FILEATTR function to obtain the actual MS-DOS file handle.

The syntax for getting the file handle is as follows: FILEATTR(filenumber, 2) The program example below shows how to obtain the MS-DOS file handle of a file using the FILEATTR function. The program then uses the file handle in an MS-DOS INTERRUPT call to return the file's date and time stamp.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS, and to Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS.



MORE INFORMATION
The FILEATTR function is not available with QuickBasic versions earlier than Version 4.00.

This code example invokes MS-DOS interrupt 21 hex (33 decimal) with function 57 hex (87 decimal) to get a file's date and time stamp from the file's directory entry. This interrupt requires an MS-DOS file handle as an argument. Basic's FILEATTR function is used to retrieve the file handle before invoking the interrupt.

Code Example
DEFINT A-Z REM $INCLUDE: 'qb.bi' REM In Basic PDS 7.00 you must instead include 'qbx.bi' REM In QB.EXE, use QB /L QB.QLB. In QBX.EXE, use QB /L QBX.QLB. REM In BC.EXE for QuickBasic 4.00, 4.00b, 4.50, or Basic Compiler REM 6.00, 6.00B, link with QB.LIB. In BC.EXE for Basic PDS 7.00, REM link with QBX.LIB. (To support the CALL INTERRUPT statement.)

DIM inregs AS RegType, outregs AS RegType ON ERROR GOTO ErrorHandler CLS INPUT &quot;Enter filename:&quot;, filename$

OPEN filename$ FOR INPUT AS #1 filename$ = filename$ + CHR$(0) ' ASCIIZ (Null on end) inregs.ax = &H5700 inregs.bx = FILEATTR(1, 2)      ' Get DOS File Handle CALL INTERRUPT(&H21, inregs, outregs)

REM Date is returned in outregs.dx. REM  Day   : Bits 0-4 REM  Month : Bits 5-8 REM  Year  : Bits 9-15 (from 1980) Day = outregs.dx AND 31               ' Mask the upper bits Month = (outregs.dx \ 2 ^ 5) AND 15   ' Shift L 5 & mask upper bits Year = 1980 + (outregs.dx \ 2 ^ 9)    ' Shift left 9 & add 1980 PRINT &quot;Month =&quot;; Month; &quot; Day =&quot;; Day; &quot;  Year =&quot;; Year

REM Time is returned in outregs.cx REM  Seconds : Bits 0-4 (2 second increments) REM  Minutes : Bits 5-10 REM  Hours   : Bits 11-15 seconds = 2 * (outregs.cx AND 31) ' Mask the upper bits & mult. by 2 minutes = (outregs.cx \ 2 ^ 5) AND 63 ' Shift L 5 & mask upper bits hours = outregs.cx    ' Shift left 11 - Be sure to shift in zeros! hours = hours \ 2 hours = hours AND 32767 hours = hours \ 2 ^ 10 PRINT &quot;Sec =&quot;; seconds; &quot; Min =&quot;; minutes; &quot;  Hours =&quot;; hours SHELL &quot;dir &quot; + filename$ CLOSE #1 END

ErrorHandler: IF ERR = 53 THEN   ' File Not Found PRINT &quot;Incorrect path or File does not exist&quot; ELSE PRINT ERR END IF       END

Additional query words: QuickBas BasicCom

Keywords: KB38492

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.