Diesel Expression to Display Part of File Path in a Field

Diesel Expression to Display Part of File Path in a Field

neabailey
Enthusiast Enthusiast
473 Views
3 Replies
Message 1 of 4

Diesel Expression to Display Part of File Path in a Field

neabailey
Enthusiast
Enthusiast

Hello, Is there a way to have a field display only a portion of the file path? A saw a similar post but referring to file name only, here: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/diesel-expression-to-display-part-of...

 

I'm looking for something similar but with file path. The first part of the path that I don't want to show looks like this : X: \XXXXXX\## XXX\XXXXXXX\

everything after that I want to show, including the file name.

Is it possible to write something that states that everything before the 4th backslash should be ignored and everything else is shown?

0 Likes
474 Views
3 Replies
Replies (3)
Message 2 of 4

neabailey
Enthusiast
Enthusiast
@doni49 I'll tag you since you helped with a similar situation
0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

Maybe something like this using getfile

 

 

; thanks to Lee-mac for this defun
(defun csv->lst ( str / pos )
(if (setq pos (vl-string-position 42 str))
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
    (list str)
    )
)

(setq str "D:\\Bigal\\stuff\\20090909-photo\\P1010001.JPG")

(while (VL-STRING-POSITION 92 str)
(setq str (vl-string-subst "*" "\\" str 1))
)

(setq ans (csv->lst  str ))

 

 ("D:" "Bigal" "stuff" "20090909-photo" "P1010001.JPG")

("X:" "XXXXXX" "## XXX" "XXXXXXX" "")

 

Just join back what you want as a string.

0 Likes
Message 4 of 4

john.uhden
Mentor
Mentor

@neabailey 

At first I misunderstood your intent, so we have @shrinkstr1.

Then I read again, so we have @shrinkstr2.

(defun @shrinkstr1 (str / pos i str1 str2)
  (vl-load-com)
  (setq i 0 pos 0)
  (while (< i 4)
    (if (setq pos (vl-string-search "\\" str (1+ pos)))
      (setq i (1+ i))
      (setq i 5)
    )
  )
  (setq str1 (substr str 1 (setq i (1+ pos))))
  (while (setq i (vl-string-search "\\" str (1+ i)))
    (setq pos i)
  )
  (setq str2 (substr str (+ pos 2)))
  (strcat str1 "..." str2)
)
(defun @shrinkstr2 (str / pos i str1 str2)
  (vl-load-com)
  (setq i 0 pos 0)
  (while (< i 4)
    (if (setq pos (vl-string-search "\\" str (1+ pos)))
      (setq i (1+ i))
      (setq i 5)
    )
  )
  (substr str (1+ pos))
)

John F. Uhden

0 Likes