Visual Basic Customization

Visual Basic Customization

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

Get folder name in path

274 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,582
Registered: ‎06-29-2007
Message 2 of 4 (265 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 (256 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 (243 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.