VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get folder name in path

3 REPLIES 3
Reply
Message 1 of 4
XIJIANGWOO
925 Views, 3 Replies

Get folder name in path

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

3 REPLIES 3
Message 2 of 4

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4
XIJIANGWOO
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.

Message 4 of 4
bojko108
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost