How to get a particular value using RegEx

I want to get only the “DirectoryName” from the absolute path below

“C:\Users\Kiruba\Documents\DirectoryName”.

Since we have multiple backslashes in this path, how to get only the last value of the path.

Can someone help me with the regex function? Or if you have any other solution to get, I welcome that too.

Use Path.GetFileName("C:\\Users\\Kiruba\\Documents\\DirectoryName")

Even though the function name is misleading, it will get the job done.

1 Like

you can try this @Kirubakaran_Kannan

1 Like

@Kirubakaran_Kannan Adding one more Solution using Split Method :

Split(yourFolderPath,"\")(Split(yourFolderPath,"\").Count-1) .ToString

2 Likes

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