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

Get folder name up one level.

3 REPLIES 3
Reply
Message 1 of 4
XIJIANGWOO
851 Views, 3 Replies

Get folder name up one level.

Hi guys,

 

I am currently using this code to get the folder name containing the current drawing.

 

FolderName = Dir(ThisDrawing.path, vbDirectory)

 What would I use if I wanted to get the foldername one level up (third)?

 

ex. C:\FIRST\SECOND\THIRD\FOURTH

 

Any help is greatly appreciated.

 

Shawn

 

 

3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: XIJIANGWOO


@XIJIANGWOO wrote:

....

What would I use if I wanted to get the foldername one level up (third)?

ex. C:\FIRST\SECOND\THIRD\FOURTH

....


I don't know about that kind of code, but in AutoLISP terms:

 

If

 

(setq filepath (getvar 'dwgprefix))

 

returns
 

"K:\\FIRST\\SECOND\\THIRD\\FOURTH\\"

 

then you can trim off after the next-to-last \ character:

 

(substr

  filepath

  1

  (1+

    (vl-string-position

      (ascii "\\")
      (vl-string-right-trim "\\" filepath)

      nil T

    ); vl-string-position

  ); 1+

); substr

 

returns
 

"K:\\FIRST\\SECOND\\THIRD\\"

Kent Cooper, AIA
Message 3 of 4
pbejse
in reply to: XIJIANGWOO

One folder down

 

(findfile
(strcat (getvar 'dwgprefix)
"..")
)

 

HTH

 

 

 

Message 4 of 4
BigDumbWeirdo
in reply to: XIJIANGWOO

@XIJIANGWOO wrote:

Hi guys,

 

I am currently using this code to get the folder name containing the current drawing.

 

FolderName = Dir(ThisDrawing.path, vbDirectory)

 What would I use if I wanted to get the foldername one level up (third)?

 

ex. C:\FIRST\SECOND\THIRD\FOURTH

 

Any help is greatly appreciated.

 

Shawn

 

 


FolderName = Dir(ThisDrawing.path, vbDirectory)
FolderArray = Split(FolderName, "\")
DesiredFolderName = FolderArray(FolderArray.length() - 2)

 

 I haven't tested it, but it should work as is.

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

Post to forums  

”Boost