$CPU 8086 ' make compatible with XT systems $LIB ALL OFF ' turn off all PowerBASIC libraries $ERROR ALL OFF ' turn off all PowerBASIC error checking $OPTIMIZE SIZE ' optimize for smaller code $COMPILE UNIT ' compile to a UNIT (.PBU) '$COMPILE EXE ' compile to a UNIT (.PBU) DEFINT A-Z ' Required for all numeric functions, forces PB to not ' include floating point in UNIT (makes it smaller) '/*------------------------------------------------------------------*/ $CODE SEG "MLIB1" '/*------------------------------------------------------------------*/ ' GetDTA - Get Disk Transfer Address (DTA) from DOS ' ' DtaSeg = Returned segment of the DTA ' DtaOfs = Returned offset of the DTA ' ' The DTA is usually located in the PSP. However, any routine that ' calls the FINDFIRST, FINDNEXT functions from DOS (such as the ' PowerBASIC statement DIR$) can change the location of the DTA. ' This sub-routine uses DOS interrupt 21h, function 2Fh, to get ' the current location of the DTA. ' SUB GetDTA(DtaSeg AS INTEGER, DtaOfs AS INTEGER) PUBLIC ! push DS ; save DS for PowerBASIC ! mov AX, &H2F00 ; function 2Fh, get DTA location ! int &H21 ; call DOS ! lds SI, DtaSeg ; point DS:SI at DtaSeg ! mov DS:[SI], ES ; put segment of DTA in variable ! lds SI, DtaOfs ; point DS:SI at DtaOfs ! mov DS:[SI], BX ; put offset of DTA in variable ! pop DS ; restore DS for PowerBASIC END SUB '/*------------------------------------------------------------------*/ ' Exist - Return true (-1) if a given filespec exists. Preserves the DTA. ' Calling any of the DTA routines after Exist will return invalid ' results because of the DTA preservation. ' ' Filename = name of file or directory to test for the existence of ' '/*------------------------------------------------------------------*/ ' EXIST(FILESPEC$) ' Retuns a 1 if the file exists and a zero if the file is not ' found. ' EXMAPLE: EXIST("C:\TESTER.DAT") '/*------------------------------------------------------------------*/ FUNCTION EXIST(BYVAL Filename AS STRING) PUBLIC AS INTEGER DIM DtaSeg AS INTEGER DIM DtaOFs AS INTEGER DIM OldDtaBuffer AS STRING GetDTA DtaSeg, DtaOfs DEF SEG = DtaSeg OldDtaBuffer = PEEK$(DtaOfs, 44) 'save current DTA information DEF SEG T = LEN( DIR$(Filename, 17) ) > 0 IF T = -1 THEN FUNCTION = 1 ELSE FUNCTION = 0 DEF SEG = DtaSeg POKE$ DtaOfs, OldDtaBuffer 'restore saved DTA information DEF SEG END FUNCTION '/*------------------------------------------------------------------*/ ' CLS ' PRINT "TESTING EXIST FUNCTION" ' PRINT EXIST("C:\AUTOEXEC.BAT") ' PRINT EXIST("C:\TEST.BAT") ' PRINT EXIST("C:\CONFIG.SYS") ' IF EXIST("C:\AUTOEXEC.BAT") THEN PRINT "YES" ELSE PRINT "NO" ' IF EXIST("C:\DODDLE.BAT") THEN PRINT "YES" ELSE PRINT "NO" ' INPUT Z '/*------------------------------------------------------------------*/