home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / FILEATT.ZIP / FILEATT.BAS < prev    next >
BASIC Source File  |  1994-01-18  |  3KB  |  92 lines

  1. OPTION EXPLICIT
  2. '$FORM frmDemo
  3. '
  4. 'Demonstration of how to change/read file attributes
  5. 'using VBDOS/CALL INTERRUPT. Andy Chevin 18/01/93
  6. '
  7. 'Start VBDOS as follows:
  8. ' VBDOS /l vbdos.qlb
  9. ' (include interrupt library)
  10. '
  11. '$INCLUDE: 'vbdos.bi'
  12. ' (include defines for interrupt library)
  13. '
  14. 'File Attribute Type:
  15. 'Noramlly should put Types that are referenced more than once
  16. 'in an INCLUDE file.
  17.  
  18.     TYPE FileAttType
  19.         ReadOnly AS INTEGER
  20.         Hidden AS INTEGER
  21.         System AS INTEGER
  22.         Archive AS INTEGER
  23.         Result AS INTEGER
  24.     END TYPE
  25.  
  26.     frmDemo.SHOW 1
  27.  
  28.     END
  29.  
  30. SUB GetAttrib (FileName$, Att AS FileAttType)
  31.     'file attributes for FileName$ will be returned in Att
  32.  
  33.     DIM regX AS RegTypeX   'Define local register type
  34.     DIM f$                 'variable to hold file name
  35.  
  36.     regX.ax = &H4300          'Dos Services no. 43h, 00 = Get file attributes
  37.     f$ = FileName$ + CHR$(0)  'String must be in asciiz format
  38.     regX.ds = SSEG(f$)        'Far string segment
  39.     regX.dx = SADD(f$)        'Offset of string
  40.     INTERRUPTX &H21, regX, regX    'call Dos Services
  41.  
  42.     'Check for errors
  43.     IF regX.flags AND 1 THEN    'If CF is set then error occured
  44.         Att.Result = regX.ax      '& is held in AX (std Dos Error code)
  45.     ELSE
  46.         Att.Result = 0            'No error occurred
  47.         'Bit fiddling:
  48.         'Move the relevant bits into position 0 & mask off to obtain result
  49.         'Attributes are held in CX register
  50.         'Bit 0 = ReadOnly
  51.         'Bit 1 = Hidden
  52.         'Bit 2 = System
  53.         'Bit 3 = Not used
  54.         'Bit 4 = Not used
  55.         'Bit 5 = Archive
  56.         Att.ReadOnly = regX.CX AND 1
  57.         Att.Hidden = (regX.CX \ 2) AND 1
  58.         Att.System = (regX.CX \ 4) AND 1
  59.         Att.Archive = (regX.CX \ 32) AND 1
  60.     END IF
  61.  
  62. END SUB
  63.  
  64. SUB SetAttrib (FileName$, Att AS FileAttType)
  65.     'file attributes for FileName$ will be set to values
  66.     'passed to this routine in Att
  67.  
  68.     DIM regX AS RegTypeX   'Define local register type
  69.     DIM f$                 'variable to hold file name
  70.  
  71.     regX.ax = &H4301       'Dos Services no. 43h, 01 = Set file attributes
  72.  
  73.     regX.CX = Att.ReadOnly  'Clear & Set correct attributes
  74.     regX.CX = regX.CX OR ((Att.Hidden * 2) AND 2)
  75.     regX.CX = regX.CX OR ((Att.System * 4) AND 4)
  76.     regX.CX = regX.CX OR ((Att.Archive * 32) AND 32)
  77.  
  78.     f$ = FileName$ + CHR$(0)  'String must be in asciiz format
  79.     regX.ds = SSEG(f$)      'address of string
  80.     regX.dx = SADD(f$)
  81.     INTERRUPTX &H21, regX, regX    'call Dos Services
  82.  
  83.     'Check for errors
  84.     IF regX.flags AND 1 THEN    'If CF is set then error occured
  85.         Att.Result = regX.ax      '& is held in AX (std Dos Error code)
  86.     ELSE
  87.         Att.Result = 0            'No error occurred
  88.     END IF
  89.  
  90. END SUB
  91.  
  92.