Create folder using username as folder name

Create folder using username as folder name

gccdaemon
Collaborator Collaborator
1,251 Views
7 Replies
Message 1 of 8

Create folder using username as folder name

gccdaemon
Collaborator
Collaborator

Don't need anything fancy, but I can't get this to work. I'm sure it's got something to do with strings, but I'm not good at manipulating them. Here is what I have:

(defun C:UDATE  (/ )
	(vl-load-com)
	(vl-mkdir (strcat "C:\\CAD Standards\\UPDATED\\" (getenv "username")))
	(princ)
)
Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Accepted solutions (1)
1,252 Views
7 Replies
Replies (7)
Message 2 of 8

devitg
Advisor
Advisor
Accepted solution

You need to check if such  directory exist 

 

"C:\\CAD Standards\\UPDATED\\"

I test with 

 

(vl-mkdir (strcat "C:" (getenv "username")))

 It work. 

0 Likes
Message 3 of 8

rkmcswain
Mentor
Mentor

Here is a version that works even if none or part of it exists.

 

(vl-load-com)
(defun C:UDATE  ( / a b c )
  (setq a "C:\\CAD Standards"
	b "C:\\CAD Standards\\UPDATED\\"
	c (strcat b (getenv "username"))
  )
  (if (not (vl-file-directory-p a))
    (vl-mkdir a)
  )
  (if (not (vl-file-directory-p b))
    (vl-mkdir b)
  )
  (if (not (vl-file-directory-p c))
    (vl-mkdir c)
  )
  (princ)
)
R.K. McSwain     | CADpanacea | on twitter
Message 4 of 8

devitg
Advisor
Advisor

There is any way , to open a dialog box to get the directory , like FINDFILE or some like .??

0 Likes
Message 5 of 8

rkmcswain
Mentor
Mentor

@devitg  - this may do what you want > http://www.lee-mac.com/directorydialog.html

R.K. McSwain     | CADpanacea | on twitter
Message 6 of 8

devitg
Advisor
Advisor
Thanks for it. Just what I need.
0 Likes
Message 7 of 8

ronjonp
Advisor
Advisor

FWIW .. you don't need to test if each directory exists with vl-mkdir

I would just test the final path like so ( using your code as a base ).

(defun c:udate (/ a b c)
  (setq	a "C:\\CAD Standards\\"
	b (strcat a "UPDATED\\")
	c (strcat b (getenv "username"))
  )
  (foreach d (list a b c) (vl-mkdir d))
  (if (vl-file-directory-p c)
    (print "Success!")
  )
  (princ)
)
Message 8 of 8

gccdaemon
Collaborator
Collaborator

So basically each folder needs to be there to create a new folder under it. I knew there was something simple I was missing. Thanks for the assist everyone!

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram