Author Topic: How to determine whether a directory exists, if doesn't exist, then make up it  (Read 3835 times)

0 Members and 1 Guest are viewing this topic.

jxphklibin

  • Guest
How to determine whether a directory exists, if doesn't exist, then make up the directory.
thans!

jxphklibin

  • Guest
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.
« Last Edit: March 30, 2009, 05:06:00 AM by jxphklibin »

mkweaver

  • Bull Frog
  • Posts: 352
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). which includes: (wsh-CreateFolder <FolderName>)
(thanks Tony)

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
don't forget about vl-mkdir :)

Spike Wilbury

  • Guest
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\\")))

mkweaver

  • Bull Frog
  • Posts: 352
don't forget about vl-mkdir :)
How did I miss that??? :?

jxphklibin

  • Guest
I Can not open the web:http://www.caddzone.com/

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Same here, must be blocked for us people living in China  :police:

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
findfile will also work for searching directories. not that this piece of information is useful.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jxphklibin

  • Guest
I already know how to do that!

Chris

  • Swamp Rat
  • Posts: 547
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.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10