Help me to get the folder name from a file path

Hi , i need ur help to get

example :
D:\OCDC\UAT\Data\2023\10072023\Invoices*Other Company*\my file 123.PDF

output : Other Company
Note : the FolderName could be diffrent each time bieng processed

Thanks

Hi @StevenIsRobotOnline

Try this
str_Path.Split("\".ToCharArray).Reverse()(1)

Hi,

Directory.GetDirectories(“Directory_path”)

Assign - intCounter = 0
While intCounter < arrMyArray.Length

  • Assign - arrMyArray(intCounter) = Path.GetFileName(arrMyArray(intCounter))
  • Assign - intCounter = intCounter + 1

End While

I hope this will help you

ofc why i didnt think of this way hahha,

thankss ya

Hi @StevenIsRobotOnline

Hope it helps!!

Hi @StevenIsRobotOnline

Try this:
Result = str_Path.Split("".ToCharArray).Reverse()(1)

1 Like

Hi
Try this
Input= “D:\OCDC\UAT\Data\2023\10072023\InvoicesOther Company\my file 123.PDF”
In Assign
Output= input.Split(“"c)(input.Split(”"c).Count-2)
Result= Invoices**Other Company* *

sure thanks ,

i will wait for a while in case someone can give other efficient way to do it ,
but so far i think this the best and what i had in mind

thanks

You can use regular expression to search for the text between “Invoices” and “\”. Refer to the screenshot below.

image

Hi @StevenIsRobotOnline

You can use the regular expressions to get the required output. Use the below regex to extract the output.

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=\\w**).(?=*\\w))”)

Hope it helps!!

@StevenIsRobotOnline

As this is a path…it would be good to use path related commands

Path.GetFileName(Path.GetDirectoryName("YourPath"))

or

new DirectoryInfo(System.IO.Path.GetDirectoryName("YourPath")).Name

cheers

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.