home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / ISDIR87.ZIP / ISDIR.DOC < prev   
Encoding:
Text File  |  1988-02-10  |  5.1 KB  |  160 lines

  1. ISDIR(): An assembly language function
  2. By Don L. Powells
  3.  
  4. Some Clipper users have inquired about a method of checking to see if a 
  5. directory path exists. During the execution of a program a user may enter
  6. a non-existent path and generate a DOS error 3 (path not found). This, of
  7. course, is a critical error from which it is rather difficult to recover. I
  8. was therefore inspired to write the function whose source code is shown below
  9. with an accompanying Clipper demonstration program. The theory behind the 
  10. program is to attempt to change to the directory being validated and if the
  11. attempt is successful, return a true to the calling program and return the 
  12. user to the original directory.
  13.  
  14. This routine can also be used to test to see if a drive exists and to
  15. test whether a floppy drive door is open or closed.  To do this, all 
  16. you have to do is to try to test if the root directory of that drive 
  17. exists.
  18.  
  19. Example usages:
  20.  
  21.   ISDIR("C:\")               && is drive C available?
  22.   ISDIR("A:\")               && is there a formatted floppy in A:?
  23.   ISDIR("C:\DATA")           && is there a directory called C:\DATA?
  24.  
  25.  
  26. ;**************************************
  27. ;Filename: fisdir.asm,.obj
  28. ;Purpose: To check to see if a specified directory path is valid
  29. ;Usage: ISDIR(expc)
  30. ;       where expc is a variable or literal string containing
  31. ;       a directory path
  32. ;Returns: Logical true if the directory exists or false if it does not.
  33. ;Notes: The program receives a parameter from a Clipper program containing
  34. ;       the directory path to be validated. It saves that segment:offset
  35. ;       pair in ES and CX. It then gets the current directory path and saves
  36. ;       it to the dir_buff. An attempt is made to change to the directory
  37. ;       path being validated. If it is successful a true value is passed back
  38. ;       to the Clipper program and the program changes back to the original
  39. ;       directory. Otherwise, it returns false.
  40. ;**************************************
  41.  
  42.  
  43. PUBLIC          ISDIR
  44.  
  45. EXTRN           _PARC:FAR
  46. EXTRN           _RETL:FAR
  47.  
  48.  
  49. CODESEG          SEGMENT BYTE    'PROG' ;PROG IS THE REQUIRED CLASS CODE
  50.                  ASSUME  CS:CODESEG     ;     FOR AUTUMN 86 CLIPPER
  51.  
  52. ISDIR   PROC    FAR
  53.  
  54. ;INITIALIZATION PROCEDURE OF SAVING THE BASE POINTER AND REGISTERS
  55.         PUSH    BP
  56.         MOV     BP,SP
  57.  
  58.         PUSH    DS
  59.         PUSH    ES
  60.         PUSH    SI
  61.  
  62. ;GET PASSED PARAMETER
  63.         MOV     AX,1
  64.         PUSH    AX
  65.         CALL    _PARC
  66.         ADD     SP,2
  67.  
  68. ;SAVE ADDRESS IN ES:CX REGISTER PAIR
  69.         MOV     ES,AX
  70.         MOV     CX,BX
  71.  
  72. ;GET CURRENT DIRECTORY PATH NAME AND SAVE TO DIR_BUFF
  73.         MOV     AH,47H
  74.         MOV     DL,0
  75.         MOV     SI,SEG DIR_BUFF
  76.         MOV     DS,SI
  77.         MOV     SI,OFFSET DIR_BUFF
  78.         INT     21H
  79.  
  80. ; ATTEMPT TO CHANGE TO NEW DIRECTORY
  81.         PUSH    ES
  82.         POP     DS
  83.         MOV     DX,CX
  84.         MOV     AH,3BH
  85.         INT     21H
  86.  
  87.         MOV     CX,0    ;SET RETURN VALUE TO DEFAULT OF FALSE
  88.         JC      NOPATH
  89.  
  90. ; IF NEW DIRECTORY EXISTS SET RETURN VALUE TO TRUE AND RETURN TO ORIGINAL
  91. ; DIRECTORY
  92.         MOV     CX,1
  93.         MOV     AH,3BH
  94.         PUSH    CS
  95.         POP     DS
  96.         MOV     DX,OFFSET BK_SLASH
  97.         INT     21H
  98.  
  99. ;TERMINATION PROCEDURE
  100. NOPATH:
  101.         POP     SI
  102.         POP     ES
  103.         POP     DS
  104.         POP     BP
  105.  
  106. ;RETURN LOGICAL TRUE OR FALSE
  107.         MOV     AX,CX
  108.         PUSH    AX
  109.         CALL    _RETL
  110.         POP     AX
  111.         RET
  112. ISDIR           ENDP
  113. BK_SLASH        DB      '\'
  114. DIR_BUFF        DB      65 DUP(0)
  115.  
  116. CODESEG         ENDS
  117.                 END
  118.  
  119.  
  120. _______________________________________
  121. * Program Name: tisdir.prg *
  122. * Author: Don L. Powells *
  123. * (c) 1987 by Nantucket Corp. *
  124. **************************************************************************
  125. * Created: 7/24/1987 at 7:00pm                                           *
  126. * main =                                                                 *
  127. * Revision: ____  Last Revised: __________ @ __:__                       *
  128. * Called From:                                                           *
  129. * -- Data Base Files --   ---- Index Files ----   ----- Other Files ---- *
  130. *                                                 fisdir.obj             *
  131. *                                                                        *
  132. *                                                                        *
  133. *************************** ALL RIGHTS RESERVED **************************
  134. * This program tests and demonstrates the ISDIR() assembly language UDF.
  135.  
  136. clear
  137. ? "                 Testing the isdir() assembly function"
  138. ?
  139. ? "Press <ESC> to quit."
  140. mpath=space(64)
  141. do while lastkey() != 27
  142.    @ 5,0 say "Enter directory path:" 
  143.    @ 6,0 get mpath picture "@k"
  144.    read
  145.    mpath = trim(mpath)
  146.    if isdir(mpath)
  147.       @ 23,1
  148.       @ 23,1 say "Directory exists!"
  149.    else
  150.       @ 23,1
  151.       @ 23,1 say "Directory does not exist!"
  152.    endif
  153.    @ 24,1 say "Press any key to continue."
  154.    inkey(0)
  155.    mpath = mpath + space(64-len(mpath))
  156. enddo
  157. return
  158.  
  159.  
  160.