View Full Version : Check for Folder - Create if needed
madcadder
2007-03-19, 06:08 PM
I need to modify this to check to see if the path exists and create the path if it does not exist.
(SETQ |path|
(STRCAT
"c:\\Documents and Settings\\"
|loginname|
"."
|domain|
"\\My Documents\\Customer Files\\Inquiry Number\\"
) ;_ end of strcat
) ;_ end of setq
"\\Customer Files\\Inquiry Number\\" would be the only part that currently does not exist. After the original creation of "\\Customer Files" "\\Inquiry Number\\" would be the only part that changes and could be missing. Either way, I need to make sure the entire path exists so I can create if needed.
I never done this with folders.
TIA
(SETQ |path|
(STRCAT
"c:\\Documents and Settings\\"
|loginname|
"."
|domain|
"\\My Documents\\Customer Files"
) ;_ end of strcat
) ;_ end of setq
(if (not (vl-file-directory-p |path|))
(vl-mkdir |path|)
)
(setq |path| (strcat |path| "\\Inquiry Number"))
(if (not (vl-file-directory-p |path|))
(vl-mkdir |path|)
)
HTH,
Jeff
madcadder
2007-03-19, 07:14 PM
(if (not (vl-file-directory-p |path|))
(vl-mkdir |path|)
)
HTH,
Jeff
Bingo! That's the part I didn't know how to do.
Thank ya sir!
You're welcome. I should note that I responded to your question and just answered what you asked. But in this case I should have added that no check is required. Just issue the (vl-mkdir) function, it will either get created if it needs to or ignored if it already exists. Although you do need to create each one.....it won't add multiple folders at once.
madcadder
2007-03-19, 07:54 PM
You're welcome. I should note that I responded to your question and just answered what you asked. But in this case I should have added that no check is required. Just issue the (vl-mkdir) function, it will either get created if it needs to or ignored if it already exists. Although you do need to create each one.....it won't add multiple folders at once.
So you are saying I need to make sure the parent exists before making any sub-folders.
If I have:
c:\working files\project a\
it will create a sub folder "phase 1".
but if I only have
c:\working files\
it will not create "project a\" and "phase 1\" in one VL-MKDIR.
Correct?
madcadder
2007-03-19, 08:56 PM
This is the local version without the dialog box I tested:
;;;
;;; NewProject.lsp
;;;
;;; Copyright © 2007 by Tod Winn
;;;
;;;-------------------------------------------------------------------------
;;; DESCRIPTION:
;;; For creating new project folders correctly.
;;;
;;;-------------------------------------------------------------------------
;;;
;;; Version 1.01 - Tod Winn - Changed from command line to dialog box interface.
;;; Version 1.02 - Tod Winn - Changed from server to local path. Check if path exists, create as needed.
;;; needs error code
(DEFUN run_dialog (/)
(SETQ |foldername| (GET_TILE "|foldername|"))
(PRINC)
) ;_ end of DEFUN
(DEFUN display_newproject_dialog (/)
(SETQ |dialog| (LOAD_DIALOG "newproject.dcl"))
(IF (NOT (NEW_DIALOG "NEWPROJECT" |dialog|))
(SETQ |foldername| (GETSTRING "Enter Inquiry Number: "))
) ;_ end of if
(ACTION_TILE
"accept"
"(run_dialog) (done_dialog)"
) ;_ end of ACTION_TILE
(ACTION_TILE "cancel" "(done_dialog) (exit)")
(START_DIALOG)
(UNLOAD_DIALOG |dialog|)
(PRINC)
) ;_ end of defun
(DEFUN c:newproject (/ |cprofile|
|dws| |foldername|
|path| |projectname|
|projectstandards|
|reg-key1| |reg-key2|
|standardsfile| |templatepath|
)
(VL-LOAD-COM)
(display_newproject_dialog)
(SETQ |cprofile| (GETVAR "cprofile"))
(SETQ |dws| "CAD Standards.dws")
;;; (SETQ |foldername| (GETSTRING "Enter New Folder Name: ")) - omitted for v1.01
;;; (SETQ |path| "M:\\Customer Files\\Inquiry Number\\") - omitted for v1.02
(SETQ |path| "C:\\Customer Files")
(IF (NOT (VL-FILE-DIRECTORY-P |path|))
(VL-MKDIR |path|)
) ;_ end of if
(SETQ |path| (STRCAT |path| "\\Inquiry Number\\"))
(IF (NOT (VL-FILE-DIRECTORY-P |path|))
(VL-MKDIR |path|)
) ;_ end of if
(SETQ |projectname| (STRCAT |path| |foldername|))
(SETQ |reg-key1|
(STRCAT "HKEY_CURRENT_USER\\"
(VLAX-PRODUCT-KEY)
"\\profiles\\"
|cprofile|
"\\General\\"
) ;_ end of STRCAT
) ;_ end of setq
(SETQ |reg-key2|
(STRCAT "HKEY_CURRENT_USER\\"
(VLAX-PRODUCT-KEY)
"\\Profiles\\"
|cprofile|
"\\Dialogs\\Sheet Set Wizard"
) ;_ end of STRCAT
) ;_ end of setq
(SETQ |templatepath|
(VL-REGISTRY-READ |reg-key1| "TemplatePath")
) ;_ end of setq
(SETQ |standardsfile| (STRCAT |templatepath| "\\" |dws|))
(SETQ |projectstandards| (STRCAT |projectname| "\\" |dws|))
(VL-MKDIR |projectname|)
(VL-FILE-COPY |standardsfile| |projectstandards|) ;_ end of VL-FILE-COPY
(VL-REGISTRY-WRITE
|reg-key2|
"sheetSetCreatePath"
|projectname|
) ;_ end of VL-REGISTRY-WRITE
(COMMAND "_.newsheetset")
(WHILE (= (GETVAR "CMDACTIVE") 1) (COMMAND pause))
(PRINC)
) ;_ end of defun
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.