Microsoft KB Archive/45423

From BetaArchive Wiki
Knowledge Base


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

Article ID: 45423

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 Professional Development System 7.0
  • Microsoft BASIC Professional Development System 7.1
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 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
                


Additional query words: QuickBas BasicCom

Keywords: KB45423