Check to see if file exists
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
Quote:
Initializing...bad argument type: FILE nil
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.
RE: Check to see if file exists
Hi
Have you looked at the AutoLISP founction...
(findfile "filename")
Have a good one, Mike
RE: Check to see if file exists
Thanks Mike, that is exactly what I am looking for
RE: Check to see if file exists
Hi ccowgill,
or other way
(dos_filep "D:/YBI/ADESU/X5505.txt")
Quote:
Originally Posted by ccowgill
Thanks Mike, that is exactly what I am looking for
RE: Check to see if file exists
Quote:
Originally Posted by Adesu
Hi ccowgill,
or other way
(dos_filep "D:/YBI/ADESU/X5505.txt")
. . .but only if you have doslib installed.
: ) Happy Computing !
kennet
RE: Check to see if file exists
Is there a way to see if a particular routine or file is loaded?
RE: Check to see if file exists
(atoms-family 0 ) or (atoms-family 1 )
(arx)
and (dos_lisplist T ) if installed
: ) Happy Computing !
kennet
RE: Check to see if file exists
RE: Check to see if file exists
Quote:
Originally Posted by ccowgill
where can I get Doslib?
Hi
DOSLib via McNeel
Have a good one, Mike
RE: Check to see if file exists
Quote:
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.