TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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!
-
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.
-
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:-(
(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)
-
don't forget about vl-mkdir :)
-
don't forget about vl-mkdir :)
yep.... like an example of:
(defun CreateXcopyFolder ()
(if (not (vl-file-directory-p "C:\\eXcopy\\"))
(vl-mkdir "C:\\eXcopy\\")))
-
don't forget about vl-mkdir :)
How did I miss that??? :?
-
I Can not open the web:http://www.caddzone.com/
-
Same here, must be blocked for us people living in China :police:
-
findfile will also work for searching directories. not that this piece of information is useful.
-
I already know how to do that!
-
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.