Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Check to see if file exists

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default 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
    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.

  2. #2
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: Check to see if file exists

    Hi

    Have you looked at the AutoLISP founction...

    (findfile "filename")

    Have a good one, Mike

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Check to see if file exists

    Thanks Mike, that is exactly what I am looking for

  4. #4
    I could stop if I wanted to
    Join Date
    2003-11
    Posts
    277
    Login to Give a bone
    0

    Default 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

  5. #5
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default 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

  6. #6
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Check to see if file exists

    Is there a way to see if a particular routine or file is loaded?

  7. #7
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Check to see if file exists

    (atoms-family 0 ) or (atoms-family 1 )

    (arx)

    and (dos_lisplist T ) if installed

    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2006-04-07 at 05:52 PM. Reason: DosLib

  8. #8
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Check to see if file exists

    where can I get Doslib?

  9. #9
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default 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

  10. #10
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default 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.

Page 1 of 2 12 LastLast

Similar Threads

  1. 2010: error: Unable to load customization file That customization Group already exists
    By aheintze351177 in forum AutoCAD 3D (2007 and above)
    Replies: 0
    Last Post: 2013-01-09, 10:06 PM
  2. Replies: 0
    Last Post: 2011-05-30, 07:07 AM
  3. Visual Lisp Help - Check if URL Exists
    By caddog71 in forum AutoLISP
    Replies: 13
    Last Post: 2010-10-19, 02:18 AM
  4. Check if Custom Drawing Property exists
    By ccowgill in forum AutoLISP
    Replies: 9
    Last Post: 2007-08-29, 01:07 PM
  5. Need help verifying file exists
    By stephen.coff in forum AutoLISP
    Replies: 3
    Last Post: 2006-09-18, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •