home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / WINER.ZIP / CHAP11-6.BAS < prev    next >
BASIC Source File  |  1992-05-13  |  1KB  |  47 lines

  1. '*********** CHAP11-6.BAS - demonstrates testing if a file exists
  2.  
  3. 'Copyright (c) 1992 Ethan Winer
  4.  
  5. DEFINT A-Z
  6. '$INCLUDE: 'REGTYPE.BI'
  7.  
  8. DIM Registers AS RegType
  9.  
  10. TYPE DTA                         'used by DOS services
  11.   Reserved  AS STRING * 21       'reserved for use by DOS
  12.   Attribute AS STRING * 1        'the file's attribute
  13.   FileTime  AS STRING * 2        'the file's time
  14.   FileDate  AS STRING * 2        'the file's date
  15.   FileSize  AS LONG              'the file's size
  16.   FileName  AS STRING * 13       'the file's name
  17. END TYPE
  18. DIM DTAData AS DTA
  19.  
  20.  
  21. DEF FnFileExist% (Spec$)
  22.   FnFileExist% = -1              'assume the file exists
  23.  
  24.   Registers.DX = VARPTR(DTAData) 'set a new DOS DTA
  25.   Registers.DS = VARSEG(DTAData)
  26.   Registers.AX = &H1A00
  27.   CALL InterruptX(&H21, Registers, Registers)
  28.  
  29.   Spec$ = Spec$ + CHR$(0)        'DOS needs ASCIIZ string
  30.   Registers.AX = &H4E00          'find file name service
  31.   Registers.CX = 39              'attribute for any file
  32.   Registers.DX = SADD(Spec$)     'show where the spec is
  33.   Registers.DS = SSEG(Spec$)     'use this with PDS
  34.  'Registers.DS = VARSEG(Spec$)   'use this with QB
  35.  
  36.   CALL InterruptX(&H21, Registers, Registers)
  37.   IF Registers.Flags AND 1 THEN FnFileExist% = 0
  38. END DEF
  39.  
  40.  
  41. INPUT "Enter a file name or specification: ", FileSpec$
  42. IF FnFileExist%(FileSpec$) THEN
  43.    PRINT FileSpec$; " does exist"
  44. ELSE
  45.    PRINT "Sorry, no files match "; FileSpec$
  46. END IF
  47.