Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Return name of different folders

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
kpennell
366 Views, 8 Replies

Return name of different folders

Hello all,

 

The following gives me the first folder string, with no back-slashes, that the drawing exists in.

 

(setq FirstFolder
 ((lambda (/ tmpDir tmpPos)
 (substr
 (setq tmpDir (getvar "dwgprefix"))
 (+ 2 (setq tmpPos (vl-string-search "\\" tmpDir)))
 (- (vl-string-search "\\" tmpDir (1+ tmpPos)) (1+ tmpPos))))))

 

Is there a way to find the name of the second folder?

 

Is there a way to find the name of the third folder?

 

The string length of the characters for each of the first, second, third (and so on) folders are different, which means I can't count character using the "substr" function.

 

Thanks

KP

8 REPLIES 8
Message 2 of 9
Kent1Cooper
in reply to: kpennell


@kpennell wrote:

Hello all,

 

The following gives me the first folder string, with no back-slashes, that the drawing exists in.

.... 

Is there a way to find the name of the second folder?

 

Is there a way to find the name of the third folder?

....


One way is to use one of the many examples of string-splitting-up routines on this forum.  Just one example is the sdtol function [it stands for String Delimited to List] here.  If you apply it as in the first usage example there, you'll get a list from which you can easily extract any of the folder names using (cadr)/(caddr)/etc., or using (nth).

Kent Cooper, AIA
Message 3 of 9
kpennell
in reply to: Kent1Cooper

Hmm, I don't see that function in the help literature through AutoCAD.

 

I'll certainly be looking what I can see on this discussion group.

 

Thanks again KC

Message 4 of 9
alanjt_
in reply to: kpennell

(defun AT:Str2Lst (s d / i l d)
  ;; Convert string to list, based on separator
  ;; s - String to convert
  ;; d - Delimeter to break string into items
  ;; Ex. - (AT:Str2Lst "1,2,3" ",") -> '("1" "2" "3")
  ;; Alan J. Thompson, 11.11.09 / 04.01.10
  (while (setq i (vl-string-search (strcase d) (strcase s)))
    (setq l (cons (substr s 1 i) l)
          s (substr s (+ i 1 (strlen d)))
    )
  )
  (vl-remove "" (reverse (cons s l)))
)

 

 

eg.

(AT:Str2Lst (getvar 'DWGPREFIX) "\\")

 

Message 5 of 9
alanjt_
in reply to: alanjt_

Oops, if you want the third item in the list:

 

(caddr (AT:Str2Lst (getvar 'DWGPREFIX) "\\"))

 

Message 6 of 9
Kent1Cooper
in reply to: kpennell


@kpennell wrote:

Hmm, I don't see that function in the help literature through AutoCAD.

....


No, you won't find it there -- I wrote it.  It's similar in many ways to others on the forum, but if I recall, many of the others work with single characters such as commas or spaces as delimiters [which is also viable in your situation, since as someone else pointed out, "\\" is really a single character in AutoLISP], but in (sdtol) I was going for the possibility of multiple-character delimiters, as you can see from the description there that uses "Mickey Mouse" as a delimiter.

Kent Cooper, AIA
Message 7 of 9
BlackBox_
in reply to: alanjt_


@alanjt_ wrote:
(defun AT:Str2Lst (s d / i l d)
  ;; Convert string to list, based on separator
  ;; s - String to convert
  ;; d - Delimeter to break string into items
  ;; Ex. - (AT:Str2Lst "1,2,3" ",") -> '("1" "2" "3")
  ;; Alan J. Thompson, 11.11.09 / 04.01.10
  (while (setq i (vl-string-search (strcase d) (strcase s)))
    (setq l (cons (substr s 1 i) l)
          s (substr s (+ i 1 (strlen d)))
    )
  )
  (vl-remove "" (reverse (cons s l)))
)

 

 

eg.

(AT:Str2Lst (getvar 'DWGPREFIX) "\\")

 


Interesting approach... Here's one I just posted a bit ago... And another for FilePaths.



"How we think determines what we do, and what we do determines what we get."

Message 8 of 9
kpennell
in reply to: Kent1Cooper

KC,

 

Once again, I've accepted your response as the solution to my post.  Huge Thanks.  I can see this being very powerful for other applications.

 

KP

Message 9 of 9
Kent1Cooper
in reply to: kpennell


@kpennell wrote:

KC,

 

Once again, I've accepted your response as the solution to my post.  Huge Thanks.  I can see this being very powerful for other applications.

 

KP


Thank you -- it's good to know that routines written for a specific request are finding application to different [however slightly in this case] purposes.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost