FUNCTION DirExist, directory ; This function is written to tell if a directory exists or not. ; It returns 0 if the directory does NOT exist, 1 otherwise. ; Save the current directory. CD, Current=currentDirectory ; Use the Catch error handler to catch the case where we ; try to CD to a directory that doesn't exist. Catch, error IF (error NE 0) THEN BEGIN ; Directory must not exist. Return 0. RETURN, 0 ENDIF ; Try to CD to the directory. If it doesn't exist, an error occurs. CD, directory ; Well, the directory MUST exist if we are here! Change back to ; the current directory and return a 1. CD, currentDirectory RETURN, 1 END