home *** CD-ROM | disk | FTP | other *** search
/ ftp.shrubbery.net / 2015-02-07.ftp.shrubbery.net.tar / ftp.shrubbery.net / pub / pc / unix / unx.arc / EXIST.ASM < prev    next >
Assembly Source File  |  1985-06-10  |  2KB  |  75 lines

  1.     page    66,132
  2.     page
  3.  
  4. ;---- Exist.com ---------------------------------------------------------------
  5. ; Usage: exist filespec
  6. ; Sets errorlevel = {0 if file exists; 1 if file doesn't exist}
  7. ; Wildcards allowed in filename; forward or backslashes allowed in pathspec.
  8. ; DRK 30 June 84
  9. ; Example of use inside batch file:
  10. ;   exist /bin/%1
  11. ;   if errorlevel 1 goto nofile
  12. ; Note: remember that "errorlevel 0" is (errlev >= 0), a tautology.
  13. ;------------------------------------------------------------------------------
  14.     extrn    _args:near,argc:word,argv:word
  15.  
  16. stderr    equ    2
  17.  
  18.  
  19. code    segment    public 'CODE'
  20. assume cs:code,ds:code
  21.  
  22.     org    100h
  23.  
  24. ; This is a .COM program.
  25. ; It takes one argument- the name of a file (wildcards ok).
  26. ; If the file exists, ERRORLEVEL is set to zero; otherwise to one.
  27. ; The argument is the first nonblank string of chars.
  28. ; Either backslashes or forward slashes may be used in a pathname.
  29.  
  30. exist    proc    near
  31.  
  32.     ; Get arguments.
  33.     call    _args
  34.  
  35.     ; Check # of arguments- if not exactly one, send usage message.
  36.     cmp    argc,1
  37.     jnz    usage
  38.  
  39.     ; call DOS to see if file exists.
  40.     mov    dx, argv[2]    ; get pointer to first argument.
  41.     mov    ah, 4eh
  42.     mov    cx, 0        ; no special attribute bits set
  43.     int    21h        ; call DOS
  44.  
  45.     jc    nofile        ; if carry set, no file found.
  46. exok:    mov    al,0        ; errorlevel= 0 => file found
  47.     jmp    short exit
  48. nofile:    mov    al,1        ; errorlevel = 1 => no file found
  49. exit:    mov    ah,4ch
  50.     int    21h        ; terminate process, return status in AL.
  51.  
  52. ulen    = 0
  53. ulen    =    uend-uoff
  54.  
  55. usage:    mov    bx, stderr    ; write to error device...
  56.     mov    cx, ulen
  57.     mov    dx, offset umsg
  58.     mov    ah, 40h
  59.     int    21h
  60.     mov    al, 2        ; error2 = syntax error
  61.     jmp    exit
  62.  
  63. exist    endp
  64.                     
  65. umsg    db    'Usage: exist filespec', 13, 10
  66. bugo    db    ?
  67. uoff    equ    offset umsg
  68. uend    equ    offset bugo
  69.  
  70. code    ends
  71.  
  72.     end    exist
  73.