Get folder name in path

Get folder name in path

Anonymous
Not applicable
1,406 Views
3 Replies
Message 1 of 4

Get folder name in path

Anonymous
Not applicable

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

0 Likes
1,407 Views
3 Replies
Replies (3)
Message 2 of 4

Alfred.NESWADBA
Consultant
Consultant

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
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 4

Anonymous
Not applicable

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.

0 Likes
Message 4 of 4

Anonymous
Not applicable

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

0 Likes