Visual Basic Customization

Visual Basic Customization

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

Get folder name in path

260 Views, 3 Replies
09-14-2012 03:21 PM

Hi guys,

 

I am currently using this code to get the folder name (fourth) 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*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 2 of 4 (251 Views)

Re: Get folder name in path

09-15-2012 01:53 AM in reply to: XIJIANGWOO

Hi,

 

use function SPLIT (>>>details<<<) with "\" as separator to get an array of directories building up the path.

Remove the last item of that array.

Use function JOIN (>>>details<<<) to create a string of this array.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
XIJIANGWOO
Posts: 67
Registered: ‎11-19-2008
Message 3 of 4 (242 Views)

Re: Get folder name in path

09-15-2012 08:25 AM in reply to: XIJIANGWOO

I will explore that, I'm not fluent in coding,  Will that work if the folder one level up is not always the same?  Basically I am trying to take a folder name that is one level up from the parent folder and put it into a titleblock. The code

FolderName = Dir(ThisDrawing.path, vbDirectory)

 

allows me to grab the name of the file's parent folder whatever name that may be and put it into the drawing  titleblock.

 

Thanks for all of the help.

Valued Contributor
bojko108
Posts: 61
Registered: ‎01-23-2011
Message 4 of 4 (229 Views)

Re: Get folder name in path

09-16-2012 07:00 AM in reply to: XIJIANGWOO

As [alfred.neswadba] said you can use Split() function to get previous folders from full path. The code is in .NET but I think in VBA is similar to this:

                      string path=@"C:\FIRST\SECOND\THIRD\FOURTH";

                      string[] wtf = path.Split('\\');  

                      string first = wtf[0];                                       // first = c:

                      string second = wtf[0] + "\\" + wtf[1];            // second = "c:\\FIRST"

                      ............

 

ex01.jpg

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 or visit the Installation and Licensing Forum to get help installing your software.