Jump to content

Creating Folders and Subfolders


Earlzii

Recommended Posts

Hi,

 

I have created a lisp routine that plots PDF's and saves them into a certain folder depending on the client. As an extension of this I wanted to create a folder for each job that is worked on for that client which is pulled from a block. I have managed to create a folder using this information but then there are 2 different types of PDF that will be required and I wanted to split these up again into 2 different folders.

 

The part that I am having trouble with is creating these 2 subfolders.

 

The folder structure should be "C:\\Users\\" UName "\\Documents\\PDF's\\Client A\\" JobName then in this folder there will be another 2 folders one called Issue and the other called Check Print. I have tried to create these 2 sub-folders but with no luck but the program runs fine without any errors.

 

I am guessing because at the time of the plot the lisp creates the folder with the JobName it can't then verify that it exists to then create the subfolders within the JobName folder. I am probably wrong but after some searching the only help I can find online is to just create one folder or something that asks for a users input. The idea behind the lisp is to ask the user some minimal questions as to sheet size and colour or mono plot etc and automate the rest so i don't really want to go down the route of adding another dialog box for the user to input where to save the PDF because this will just defeat the point.

 

(defun ClientProjectFolder ( / UName SJobDesc1 SJobDesc2 SJobDesc3 SPN   ClientProjectFolderName ClientProjectFolderNameCP ClientProjectFolderNameIssue)
(setq UName (getenv "UserName"))
(setq SJobDesc1 (showattvalue "PW_TITLE" "JOB_DESC"))
(setq SJobDesc2 (showattvalue "PW_TITLE" "JOB_DESC2"))
(setq SJobDesc3 (showattvalue "PW_TITLE" "JOB_DESC3"))
(setq SPN (strcat SJobDesc1 " " SJobDesc2 " " SJobDesc3))

(setq ClientProjectFolderName (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN))
(vl-mkdir ClientProjectFolderName)
T

(setq ClientProjectFolderNameCP (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "\\Check Print\\"))
(vl-mkdir ClientProjectFolderNameCP)
T

(setq ClientProjectFolderNameIssue (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "\\Issue\\"))
(vl-mkdir ClientProjectFolderNameIssue)
T
)

 

Forgive me if some of the variables I have created don't match I have just quickly changed the names as they were client names.

Link to comment
Share on other sites

Hi Lee,

 

I have tried this a few different ways and can't get it to work. Will it not take user defined variables within the call i.e.

(LM:createdirectory "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "\\Check Print")

I need to be able to create the directory in the users documents which is not a constant as well as the project name which will always be different.

Link to comment
Share on other sites

I used strcat and it didn't work but I have figured out the issue. The drawing that I was testing it on the attributes "JOB_DESC2" and "JOB_DESC3" are blank which is causing the creation of anything past the SPN variable to stop. These attributes are not always filled in, they are completely blank in the example I tested on is there a way to get it to work if these variables are blank because I don't really want to ignore them as it is 50/50 whether they have any information in them or not.

Link to comment
Share on other sites

OK so it appears that because the attributes are blank and I am using " " to space out the attributes this is causing the problem. Is there an alternative to using " " but that will still put a space in between the attributes.

Link to comment
Share on other sites

Not sure what the OP means by 'blanks'. But most likely the missing (showattvalue) function can return nil.

(setq SPN
 (vl-string-trim
   " "
   (strcat 
     (if SJobDesc1 SJobDesc1 "") ; Assumption: SJobDesc1 is either nil or a string.
     " "
     (if SJobDesc2 SJobDesc2 "")
     " "
     (if SJobDesc3 SJobDesc3 "")
   )
 )
)
(if (/= "" SPN)
 (setq SPN (strcat SPN "\\"))
)
...
(strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "Check Print\\")
...

Link to comment
Share on other sites

I would suggest perhaps:

(setq SPN
   (substr
       (strcat
           (if (member SJobDesc1 '(nil "")) "" (strcat " " SJobDesc1))
           (if (member SJobDesc2 '(nil "")) "" (strcat " " SJobDesc2))
           (if (member SJobDesc3 '(nil "")) "" (strcat " " SJobDesc3))
       )
       2
   )
)

In order to avoid a possible double-space.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...