home *** CD-ROM | disk | FTP | other *** search
- ISDIR(): An assembly language function
- By Don L. Powells
-
- Some Clipper users have inquired about a method of checking to see if a
- directory path exists. During the execution of a program a user may enter
- a non-existent path and generate a DOS error 3 (path not found). This, of
- course, is a critical error from which it is rather difficult to recover. I
- was therefore inspired to write the function whose source code is shown below
- with an accompanying Clipper demonstration program. The theory behind the
- program is to attempt to change to the directory being validated and if the
- attempt is successful, return a true to the calling program and return the
- user to the original directory.
-
- This routine can also be used to test to see if a drive exists and to
- test whether a floppy drive door is open or closed. To do this, all
- you have to do is to try to test if the root directory of that drive
- exists.
-
- Example usages:
-
- ISDIR("C:\") && is drive C available?
- ISDIR("A:\") && is there a formatted floppy in A:?
- ISDIR("C:\DATA") && is there a directory called C:\DATA?
-
-
- ;**************************************
- ;Filename: fisdir.asm,.obj
- ;Purpose: To check to see if a specified directory path is valid
- ;Usage: ISDIR(expc)
- ; where expc is a variable or literal string containing
- ; a directory path
- ;Returns: Logical true if the directory exists or false if it does not.
- ;Notes: The program receives a parameter from a Clipper program containing
- ; the directory path to be validated. It saves that segment:offset
- ; pair in ES and CX. It then gets the current directory path and saves
- ; it to the dir_buff. An attempt is made to change to the directory
- ; path being validated. If it is successful a true value is passed back
- ; to the Clipper program and the program changes back to the original
- ; directory. Otherwise, it returns false.
- ;**************************************
-
-
- PUBLIC ISDIR
-
- EXTRN _PARC:FAR
- EXTRN _RETL:FAR
-
-
- CODESEG SEGMENT BYTE 'PROG' ;PROG IS THE REQUIRED CLASS CODE
- ASSUME CS:CODESEG ; FOR AUTUMN 86 CLIPPER
-
- ISDIR PROC FAR
-
- ;INITIALIZATION PROCEDURE OF SAVING THE BASE POINTER AND REGISTERS
- PUSH BP
- MOV BP,SP
-
- PUSH DS
- PUSH ES
- PUSH SI
-
- ;GET PASSED PARAMETER
- MOV AX,1
- PUSH AX
- CALL _PARC
- ADD SP,2
-
- ;SAVE ADDRESS IN ES:CX REGISTER PAIR
- MOV ES,AX
- MOV CX,BX
-
- ;GET CURRENT DIRECTORY PATH NAME AND SAVE TO DIR_BUFF
- MOV AH,47H
- MOV DL,0
- MOV SI,SEG DIR_BUFF
- MOV DS,SI
- MOV SI,OFFSET DIR_BUFF
- INT 21H
-
- ; ATTEMPT TO CHANGE TO NEW DIRECTORY
- PUSH ES
- POP DS
- MOV DX,CX
- MOV AH,3BH
- INT 21H
-
- MOV CX,0 ;SET RETURN VALUE TO DEFAULT OF FALSE
- JC NOPATH
-
- ; IF NEW DIRECTORY EXISTS SET RETURN VALUE TO TRUE AND RETURN TO ORIGINAL
- ; DIRECTORY
- MOV CX,1
- MOV AH,3BH
- PUSH CS
- POP DS
- MOV DX,OFFSET BK_SLASH
- INT 21H
-
- ;TERMINATION PROCEDURE
- NOPATH:
- POP SI
- POP ES
- POP DS
- POP BP
-
- ;RETURN LOGICAL TRUE OR FALSE
- MOV AX,CX
- PUSH AX
- CALL _RETL
- POP AX
- RET
- ISDIR ENDP
- BK_SLASH DB '\'
- DIR_BUFF DB 65 DUP(0)
-
- CODESEG ENDS
- END
-
-
- _______________________________________
- * Program Name: tisdir.prg *
- * Author: Don L. Powells *
- * (c) 1987 by Nantucket Corp. *
- **************************************************************************
- * Created: 7/24/1987 at 7:00pm *
- * main = *
- * Revision: ____ Last Revised: __________ @ __:__ *
- * Called From: *
- * -- Data Base Files -- ---- Index Files ---- ----- Other Files ---- *
- * fisdir.obj *
- * *
- * *
- *************************** ALL RIGHTS RESERVED **************************
- * This program tests and demonstrates the ISDIR() assembly language UDF.
-
- clear
- ? " Testing the isdir() assembly function"
- ?
- ? "Press <ESC> to quit."
- mpath=space(64)
- do while lastkey() != 27
- @ 5,0 say "Enter directory path:"
- @ 6,0 get mpath picture "@k"
- read
- mpath = trim(mpath)
- if isdir(mpath)
- @ 23,1
- @ 23,1 say "Directory exists!"
- else
- @ 23,1
- @ 23,1 say "Directory does not exist!"
- endif
- @ 24,1 say "Press any key to continue."
- inkey(0)
- mpath = mpath + space(64-len(mpath))
- enddo
- return
-
-