Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Extract the last folder before file as String

danny.lewisA9QBW
Advocate

Extract the last folder before file as String

danny.lewisA9QBW
Advocate
Advocate
I want to get the last folder used in the filepath and extract it as a string:
eg.  C:\Vault\WorkingFolder\Folder1\Folder2\Folder3\Part.ipt
 
extract only: Folder3
 
Can someone help me out with this? I feel like I'm overthinking it and it should be like 2-3 lines of code.
0 Likes
Reply
Accepted solutions (2)
871 Views
9 Replies
Replies (9)

bradeneuropeArthur
Mentor
Mentor

Hi.

With ilogic, vba, vb.net or what?

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

danny.lewisA9QBW
Advocate
Advocate
iLogic.
0 Likes

bradeneuropeArthur
Mentor
Mentor

Dim d As System.IO.DirectoryInfo

d = New System.IO.DirectoryInfo("C:\Vault\WorkingFolder\Folder1\Folder2\Folder3\Part.ipt")

Dim s As String 
s = d.Name

MsgBox (s)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

bradeneuropeArthur
Mentor
Mentor

or 

Dim d As System.IO.FileInfo

d = New System.IO.FileInfo("C:\Vault\WorkingFolder\Folder1\Folder2\Folder3\Part.ipt")

Dim s As String 
s = d.Directory.Name

MsgBox (s)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

danny.lewisA9QBW
Advocate
Advocate

I'm getting an error message with the d.Directory.Name. The d.Name just gave the filename (as I'm sure you realized)

 

Dim d As System.IO.DirectoryInfo
MsgBox("Directory "& ThisDoc.PathAndFileName(False))
d = New System.IO.DirectoryInfo(ThisDoc.PathAndFileName(False))

Dim s As String 
s = d.Directory.Name

MsgBox ("String = " & s)

 iLogic1.JPG

 

0 Likes

bradeneuropeArthur
Mentor
Mentor

Amd the second option with fileinfo?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

JhoelForshav
Mentor
Mentor
Accepted solution

@danny.lewisA9QBW 

How about this?

Dim oFolders() As String = System.IO.Path.GetDirectoryName(ThisDoc.PathAndFileName).Split("\")
Dim oLastFolder As String = oFolders(oFolders.Count - 1)
MsgBox(oLastFolder)

danny.lewisA9QBW
Advocate
Advocate

and bonus... you did the whole thing in 2-3 lines 😛

0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

To be fair, @bradeneuropeArthur 's first suggestion works great!! You can even compress that into this short line:

MsgBox(New System.IO.FileInfo(ThisDoc.PathAndFileName).Directory.Name)

Or to store it in variable:

Dim oFolder As String = New System.IO.FileInfo(ThisDoc.PathAndFileName).Directory.Name
MsgBox(oFolder)