
Originally Posted by
ccowgill
How do you use an IF statement that checks to see if a file exists. I am running a program that starts automatically grabs the filename and path based on the current drawing's path and extracts information from it. However if the file does not exist I get the following error
I would like to avoid having the error message show up, maybe a message similar to the following to show up on the command line only
X5505.txt does not exist
Lisp routines dont seem to like it when they get an error, they stop running all together, and that makes the stuff that might follow this command not load.
Any help would be appreciated.
Hi, ccowgill
This seems like to work for me, try it
Code:
(defun isfilex (fullname / ans fso exist_flag)
(or (vl-load-com))
(setq fso (vlax-create-object "Scripting.FileSystemObject")
ans (vlax-invoke fso 'FileExists fullname)
)
(if (eq ans 0)
(progn
(alert (strcat "File " fullname " does not exist"))
(setq exist_flag nil))
(setq exist_flag T)
)
(vl-catch-all-apply
(function (lambda ()
(vlax-release-object fso)
)
)
)
exist_flag
)
(defun C:test (/ fdesc filename msg opt shortname suf wshl)
(setq shortname "X5505.txt"
filename (strcat (getvar "dwgprefix") shortname)
)
(if (isfilex filename)
(progn
;<do your stuff here>
)
(progn
(exit)
(princ)
(gc)
)
)
(princ)
)
f.