home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / qb_lib / doesfile.asm < prev    next >
Encoding:
Assembly Source File  |  1991-01-29  |  2.2 KB  |  64 lines

  1. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. ;
  3. ;     Name :    DOESFILE.ASM
  4. ;
  5. ;  Revised :    01-29-91 11:56am
  6. ;
  7. ; Overview :    This routine checks for the existence of the file specified
  8. ;        and returns an INTEGER value of -1 (TRUE) if the file exists,
  9. ;        or an INTEGER value of 0 (FALSE) if the file does not exist.
  10. ;        Note that this routine will find a file even if it is "hidden"
  11. ;        or "read-only" or "system" - the file attribute value makes no
  12. ;        difference.
  13. ;
  14. ;      Notes :    - Requires the Microsoft MACRO ASSEMBLER V 5.1 or higher for
  15. ;        successful assembly due to the use of the Microsoft simplified
  16. ;        Segment Model.
  17. ;        - This routine should be DECLAREd as an external FUNCTION
  18. ;        routine with the QuickBASIC statement -
  19. ;
  20. ;        DECLARE FUNCTION DoesFileExist%( FileName AS STRING )
  21. ;
  22. ;        which allows the rest of your program to use this FUNCTION as
  23. ;        per the following example:
  24. ;
  25. ;        IF DoesFileExist%( FileName$ + CHR$(0) ) = TRUE THEN...
  26. ;
  27. ; Parameters :    One parameter is required here, which is the name of the file
  28. ;        for which to check.  This may be a pre-defined STRING VARIABLE,
  29. ;        or an IMMEDIATE STRING.
  30. ;        NOTE: The FileName$ parameter may include a DOS drive and
  31. ;              path specifier if you wish.
  32. ;        NOTE: The FileName$ MUST END with a CHR$(0) character
  33. ;
  34. ;==============================================================================
  35.     .MODEL  MEDIUM, BASIC
  36.     .CODE
  37.  
  38. DoesFileExist    PROC    FILENAME:WORD
  39.  
  40.     mov    BX,FILENAME        ; Put address of the FileName into BX
  41.     mov    DX,[BX+2]        ; Note that DS:DX now points at the
  42.                     ;    start of ASCIIZ string
  43.  
  44.     mov    CX,16h            ; Find the file no matter what
  45.                     ;    DOS file attribute it has
  46.     mov    AX,04E00h        ; DOS "FindFirst Match" service
  47.     int    21h
  48.  
  49.     jnc    FoundTheFile
  50.     xor    AX,AX            ; If CARRY set, make AX = 0 = FALSE
  51.                     ;    (not found) for RETURN value
  52.     jmp    short ExitDoesFileExist ; If CARRY is clear, then file exists
  53.  
  54. FoundTheFile:
  55.     mov    AX,-1            ; File was found, so make AX = -1
  56.                     ;    = TRUE for RETURN value
  57.  
  58. ExitDoesFileExist:
  59.     ret                ; Back to the QB calling program
  60.  
  61. DoesFileExist    ENDP
  62.         END
  63. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64.