Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

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

Get folder name up one level.

296 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,776
Registered: ‎09-13-2004
Message 2 of 4 (291 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,500
Registered: ‎11-24-2009
Message 3 of 4 (275 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 (237 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!