Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
XIJIANGWOO
Posts: 67
Registered: ‎11-19-2008
Message 1 of 4 (271 Views)

Get folder name up one level.

271 Views, 3 Replies
09-14-2012 12:43 PM

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

 

 

*Expert Elite*
Kent1Cooper
Posts: 5,270
Registered: ‎09-13-2004
Message 2 of 4 (266 Views)

Re: Get folder name up one level.

09-14-2012 02:26 PM 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
*Expert Elite*
pbejse
Posts: 2,436
Registered: ‎11-24-2009
Message 3 of 4 (250 Views)

Re: Get folder name up one level.

09-14-2012 04:47 PM in reply to: XIJIANGWOO

One folder down

 

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

 

HTH

 

 

 

Active Contributor
BigDumbWeirdo
Posts: 46
Registered: ‎04-15-2011
Message 4 of 4 (212 Views)

Re: Get folder name up one level.

09-18-2012 06:47 AM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community