Basic's CALL INTERRUPT Can Get/Set File Attributes in MS-DOS (45423)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q45423

SUMMARY

The program below demonstrates how to use Basic's CALL INTERRUPT statement to get and set the attributes of files in MS-DOS.

MORE INFORMATION

The program below uses MS-DOS interrupt 21 hex with function 43 hex (67 decimal) to get or set file attributes.

FILEATT.BAS

DECLARE SUB showattributes (status AS INTEGER)
REM $INCLUDE: 'QB.BI'
' For QBX.EXE and BC.EXE in Basic PDS 7.00 use the include file 'QBX.BI'
' This .BI file defines the RegTypex data TYPE.

CONST SETREADONLY = &H1
CONST SETHIDDEN = &H2
CONST SETSYSTEM = &H4
CONST SETARCHIVE = &H32
DIM inregs AS RegTypex, outregs AS RegTypex
CLS
INPUT "Enter File Name (with full pathname): "; filename$

' add CHR$(0) to make an ASCIIZ (null-terminated) string:
filename$ = filename$ + CHR$(0)

inregs.ax = &H4300                    ' get file attributes
inregs.dx = SADD(filename$)   ' Offset of ASCIIZ filename.
inregs.ds = VARSEG(filename$) ' Segment of ASCIIZ filename.
' For BC.EXE and QBX.EXE from Basic PDS 7.00/7.10, substitute the
' above line with the following line:
'   inregs.ds = SSEG(filename$)

CALL INTERRUPTX(&H21, inregs, outregs)
showattributes outregs.cx

' set hidden attribute
inregs.ax = &H4301                    ' set file attributes

' mask off the volume labels directory and reserved bits
setstatus% = outregs.cx AND &H27

setstatus% = setstatus% OR SETHIDDEN ' set hidden attribute bit
inregs.cx = setstatus%
CALL INTERRUPTX(&H21, inregs, outregs)
showattributes outregs.cx

SUB showattributes (status AS INTEGER)
  PRINT
  PRINT "File Attributes Set"
  PRINT "-------------------"
  IF status% AND SETREADONLY THEN PRINT "read-only"
  IF status% AND SETHIDDEN THEN PRINT "hidden"
  IF status% AND SETSYSTEM THEN PRINT "system"
  IF status% AND 8 THEN PRINT "volume label"
  IF status% AND 16 THEN PRINT "directory"
  IF status% AND SETARCHIVE THEN PRINT "archive"
END SUB
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB45423