Reputation: 1505
I want to extract the last folder from a folder path:
path = C:\Users\z204685\tecware\RESULTS\D1369_3 (R=0) Surface Failure
I want to extract the last part, after the "\", in a new string:
newString = "D1369_3 (R=0) Surface Failure"
Maybe reversing the path string, then using the Split function with "\" and then reversing it again...Any better ideas?
Upvotes: 2
Views: 8641
Reputation: 2016
Another solution, according to @TimWilliams comment, You can achieve this using Split
and UBound
Sub test()
Dim fpath As String
Dim newString As String
Dim temp_arr As Variant
fpath = "C:\Users\z204685\tecware\RESULTS\D1369_3 (R=0) Surface Failure"
temp_arr = Split(fpath, "\")
newString = temp_arr(UBound(temp_arr))
End Sub
Upvotes: 0
Reputation: 3960
Here's my stab at it:
Sub test()
Dim testString As String
Dim test As Long
Dim output As String
testString = "C:\Users\z204685\tecware\RESULTS\D1369_3 (R=0) Surface Failure"
test = InStrRev(testString, "\")
output = Right(testString, Len(testString) - test)
End Sub
Hope it gets you close!
Upvotes: 2