TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jxphklibin on March 28, 2009, 07:23:37 AM

Title: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: jxphklibin on March 28, 2009, 07:23:37 AM
How to determine whether a directory exists, if doesn't exist, then make up the directory.
thans!
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: jxphklibin on March 28, 2009, 08:12:13 AM
How to determine whether a directory exists, if doesn't exist, then make up the directory.
thans!

I understand. Call the common dialog box in (CommonDialog) controls, you can set flags for &H800,that decimal is 2048, you can detect the illegal or non-existent directory, and also can detect whether or not the importation of illegal file name: enter a valid path can only express . If the installation of the sign, when the importation of illegal trails, indicating a warning.
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up
Post by: mkweaver on March 28, 2009, 02:54:14 PM
How to determine whether a directory exists, if doesn't exist, then make up the directory.
thans!

I wrote the following then realized there is no direct way in lisp to create a directory:-(

Code: [Select]
(defun CreateAndGetFolder(pathname / root folders)
  (setq
    folders (split pathname "/")
    root (car folders)
    )
  (foreach folder (cdr folders)
    (if (vl-file-directory-p (strcat root "/" folder))
      (princ (strcat "\nFound " (strcat root "/" folder)))
      (princ (strcat "\nNeed to create " (strcat root "/" folder)))
      )
    (if (vl-file-directory-p (strcat root "/" folder))
      (setq root (strcat root "/" folder))
      (princ (strcat "\nFailed to create " (strcat root "/" folder)))
      )
    )
  pathname
  )
(defun split( ;parse a string into a list
     str ;string to parse
     delim ;delimiter
     / ;end of formal arguments
     rtlist i
     ) ;end of local variable list
  (while (setq i (vl-string-search delim str))
    (setq
      rtlist (cons (substr str 1 i) rtlist)
      str (substr str (+ 2 i))
      )
    )
  (if (= str "")
    (setq rtlist (cons "" rtlist))
    (setq rtlist (cons str rtlist))
    )
  (reverse rtlist)
)

This problem could be resolved with Tony Tanzillo's wsh.lsp (http://www.caddzone.com/wsh.lsp (http://www.caddzone.com/wsh.lsp)). which includes: (wsh-CreateFolder <FolderName>)
(thanks Tony)
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: VovKa on March 28, 2009, 04:11:11 PM
don't forget about vl-mkdir :)
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: Spike Wilbury on March 28, 2009, 04:35:56 PM
don't forget about vl-mkdir :)


yep.... like an example of:

Code: [Select]
(defun CreateXcopyFolder  ()
  (if (not (vl-file-directory-p "C:\\eXcopy\\"))
    (vl-mkdir "C:\\eXcopy\\")))
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up
Post by: mkweaver on March 29, 2009, 12:50:36 AM
don't forget about vl-mkdir :)
How did I miss that??? :?
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up
Post by: jxphklibin on March 30, 2009, 03:40:30 AM
I Can not open the web:http://www.caddzone.com/
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: It's Alive! on March 30, 2009, 04:38:38 AM
Same here, must be blocked for us people living in China  :police:
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: alanjt on March 30, 2009, 09:42:07 AM
findfile will also work for searching directories. not that this piece of information is useful.
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: jxphklibin on April 02, 2009, 10:09:18 AM
I already know how to do that!
Title: Re: How to determine whether a directory exists, if doesn't exist, then make up it
Post by: Chris on April 02, 2009, 11:27:12 AM
vl-mkdir will create a directory if it doesnt exist and return nil if it already does or cant create it, so there really is no need for the check to see if the directory already exists, even though that is part of the OP request.