Back


Newsgroup comp.cad.autocad 46796

Directory

Subject: Re: Handling directory names in AutoLISP -- From: Morten Warankov

Articles

Subject: Re: Handling directory names in AutoLISP
From: Morten Warankov
Date: Thu, 02 Jan 1997 10:18:26 +0100
John Loeffler wrote:
> 
> 1. Are there any AutoLISP functions which provide a dialog box
> for a user-specified directory, similar to the method of using (getfiled)
> to retrieve the name of a user-specified file?
No, there are not any other Autolisp functions for this, however
getfiled gives you what you want.
> 
> I need an AutoLISP-accessible function which:
>   - Provides a dialog box interface for selecting directories.
>   - Has features similar to (getfiled):
>     -- Arguments for a dialog title and a default directory.
>     -- Ability to browse directories and different drives.
>   - Returns a directory name for empty or non-empty directories.
(getfiled) does all this. All you need in addition is a function to
strip the directory name from the return string, and if I look in my
lisp library.... here it is:
(defun expath (fname / p1 p2 pdelim)
    (setq pdelim "\\"
          p1 (strlen fname)
    )
    (while (and (> p1 0)
                (null (member (setq p2 (substr fname p1 1)) (list pdelim
"/")))
                (/= p2 ":")
           )
       (setq p1 (1- p1))
    )
    (if (> p1 0)
       (substr fname 1 p1)
       ""
    )
  )
The function takes any file description, and returns it's directory
name, thus:
(expath "d://qwe//wer.dwg") returns: "d://qwe//".
To your second question:
>2. Are there any AutoLISP-accessible functions which check for the
>existence of a
>user-specified directory, similar to the checking performed by either >(getfiled)
>or (findfile) function?
There's no built in Autolisp functions, but you can easily check it's
existance with an attempt to open a file for writing in the directory
specified. If the directory doesn't exist, the open function will return
nil.
However to delete it afterwards you must shell out to your OS and delete
it with 
(command "SHELL" "DEL MYFILE.TXT") (in WIN, DOS, NT)
which on some graphics cards may give you a shell window or screen which
may hang a few seconds.
Hope this helps,
Mortenw
Return to Top

Downloaded by WWW Programs
Byron Palmer