Getting the sub folder name to print in a column

I am writing all files in a directory and all it’s subdirectories to an excel. I have a column that prints the full path, the file name and the file type. I want another column that prints the subfolder name that the file belongs to.

I am using this code :str_output = Split(str_input,"").Last().ToString.Trim

Its printing out the file name also as it’s using .LAST, My question is how to I get it to look at the one folder back from that only

You can try using path.getfilename after retrieving all the subfolders

grafik
grafik

@Sean_Ryan1, you can use position array number in it ()
str_input=“C:\XYZ\2020\January\newsletter@uipath.com”

str_output = Split(str_input,“”)(1).ToString.Trim output = XYZ
str_output = Split(str_input,“”)(2).ToString.Trim output =2020
str_output = Split(str_input,“”)(3).ToString.Trim output =January
str_output = Split(str_input,“”)(4).ToString.Trim output = newsletter@uipath.com

@Sean_Ryan1
try this
Split(readtxt,“")(Split(readtxt,”").count-2).ToString