How to open the subfolder What i Mistake

How to open the subfolder What i Mistake

jaimuthu
Advocate Advocate
672 Views
9 Replies
Message 1 of 10

How to open the subfolder What i Mistake

jaimuthu
Advocate
Advocate
here i attached lisp code i want open the subfolder 
(defun c:aus ( / projCode baseFolderPath projectFolderPath jaiFolderPath)
  ;; Prompt user for project code (numbers only)
  (setq projCode (getstring "\nEnter project code (numbers only): "))

  ;; Check if the entered project code is not empty
  (if (not (zerop (strlen projCode)))
    (progn
      ;; Define the base folder path
      (setq baseFolderPath "D:\\MUTHU\\")
      
      ;; Check if the base folder path exists
      (if (not (vl-file-directory-p baseFolderPath))
        (progn
          (princ (strcat "\nBase folder path does not exist: " baseFolderPath))
          (princ)
        )
        (progn
          ;; Define the path pattern to search for the project folder
          (setq projectFolderPath (strcat baseFolderPath "*" projCode "*"))
          
          ;; Get the list of folders in the base directory
          (setq folderList (vl-directory-files baseFolderPath "*.*" 1))
          
          ;; Find the project folder
          (setq projectFolderFound nil)
          (foreach folder folderList
            (if (and (vl-string-search projCode folder)
                      (vl-file-directory-p (strcat baseFolderPath folder)))
              (progn
                (setq projectFolderPath (strcat baseFolderPath folder "\\"))
                (setq projectFolderFound t)
              )
            )
          )
          
          ;; If project folder is found, search for "JAI" subfolder
          (if projectFolderFound
            (progn
              ;; Check if the "JAI" folder exists
              (setq jaiFolderPath (strcat projectFolderPath "JAI\\"))
              (if (vl-file-directory-p jaiFolderPath)
                (progn
                  (princ (strcat "\nOpening: " jaiFolderPath))
                  (startapp "explorer" jaiFolderPath)
                )
                (princ "\n'JAI' folder not found.")
              )
            )
            (princ "\nProject folder not found.")
          )
        )
      )
    )
    (princ "\nNo project code entered.")
  )
  
  (princ)
)
0 Likes
673 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

What happens that indicates a mistake?  What does not happen?  Are there any messages?  Etc., etc.

Kent Cooper, AIA
0 Likes
Message 3 of 10

paullimapa
Mentor
Mentor

found following 2 problems:

1. the following lists files and not folders:

(setq folderList (vl-directory-files baseFolderPath "*.*" 1)) 

change to one of these to list folders:

(setq folderList (vl-directory-files baseFolderPath "*.*" -1)) ; lists folders
; or use nil = "*.*"
(setq folderList (vl-directory-files baseFolderPath nil -1)) ; lists folders

2. the following places the "\\" in the wrong location:

;; Check if the "JAI" folder exists
(setq jaiFolderPath (strcat projectFolderPath "JAI\\"))

"\\" should be placed before JAI like this:

;; Check if the "JAI" folder exists
(setq jaiFolderPath (strcat projectFolderPath "\\JAI"))

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 10

jaimuthu
Advocate
Advocate

ITS NOT WORK 

 

here i attached lisp code i want open the subfolder 
(defun c:aus ( / projCode baseFolderPath projectFolderPath jaiFolderPath)
  ;; Prompt user for project code (numbers only)
  (setq projCode (getstring "\nEnter project code (numbers only): "))

  ;; Check if the entered project code is not empty
  (if (not (zerop (strlen projCode)))
    (progn
      ;; Define the base folder path
      (setq baseFolderPath "D:\\MUTHU\\")
      
      ;; Check if the base folder path exists
      (if (not (vl-file-directory-p baseFolderPath))
        (progn
          (princ (strcat "\nBase folder path does not exist: " baseFolderPath))
          (princ)
        )
        (progn
          ;; Define the path pattern to search for the project folder
          (setq projectFolderPath (strcat baseFolderPath "*" projCode "*"))
          
          ;; Get the list of folders in the base directory
          (setq folderList (vl-directory-files baseFolderPath nil -1))
          
          ;; Find the project folder
          (setq projectFolderFound nil)
          (foreach folder folderList
            (if (and (vl-string-search projCode folder)
                      (vl-file-directory-p (strcat baseFolderPath folder)))
              (progn
                (setq projectFolderPath (strcat baseFolderPath folder "\\"))
                (setq projectFolderFound t)
              )
            )
          )
          
          ;; If project folder is found, search for "JAI" subfolder
          (if projectFolderFound
            (progn
              ;; Check if the "JAI" folder exists
            (setq jaiFolderPath (strcat projectFolderPath "\\JAI"))
              (if (vl-file-directory-p jaiFolderPath)
                (progn
                  (princ (strcat "\nOpening: " jaiFolderPath))
                  (startapp "explorer" jaiFolderPath)
                )
                (princ "\n'JAI' folder not found.")
              )
            )
            (princ "\nProject folder not found.")
          )
        )
      )
    )
    (princ "\nNo project code entered.")
  )
  
  (princ)
)
0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@jaimuthu wrote:

ITS NOT WORK 


Never say only that much.  See Message 2.

Kent Cooper, AIA
0 Likes
Message 6 of 10

komondormrex
Mentor
Mentor

check this

(defun c:aus (/ base_folder project_code jai_folder)
	(setq base_folder "D:\\MUTHU\\")
  	(if (= "" (setq project_code (getstring "\nEnter project code (numbers only): ")))
		(princ "\nNo project code entered.")
		(if (null (vl-file-directory-p base_folder)) 
			(princ (strcat "\nBase folder path does not exist: " base_folder))
			(if (vl-file-directory-p (strcat base_folder project_code))
				(if (vl-file-directory-p (setq jai_folder (strcat base_folder project_code "\\" "jai")))
					(startapp "explorer" jai_folder)
					(princ "\n'JAI' folder not found.")
				)
				(princ "\nProject folder not found.")
			)
		)
	)
	(princ)
)
0 Likes
Message 7 of 10

jaimuthu
Advocate
Advocate

not work

0 Likes
Message 8 of 10

paullimapa
Mentor
Mentor

sine line 31 you've already added "\\"

                (setq projectFolderPath (strcat baseFolderPath folder "\\"))

then line 41 you don't need to add "\\":

            (setq jaiFolderPath (strcat projectFolderPath "\\JAI"))

instead just include "JAI":

            (setq jaiFolderPath (strcat projectFolderPath "JAI"))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 10

komondormrex
Mentor
Mentor

@jaimuthu wrote:

not work


can't be

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

@jaimuthu wrote:

not work


That is never enough information!

Kent Cooper, AIA
0 Likes