Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we split the Filepath from the last folder in C#?

Tags:

c#-4.0

For example i have a file ISample.cs in this path like

"D:\TEST_SOURCE\CV\SOURCE CODE\ARMY.Data\ProceduresALL\ISample.cs"

Here i wanna the file-path from

"ProceduresAll\ISample.cs"

Before that i don't wanna that path.Here i am using folder browser for choosing the folder.

Please help me regarding this.

like image 300
Hemant Kumar Avatar asked Dec 01 '22 09:12

Hemant Kumar


1 Answers

You mean like this?

string path = @"D:\TEST_SOURCE\CV\SOURCE CODE\ARMY.Data\ProceduresALL\ISample.cs";

//ISample.cs
Path.GetFileName(path);

//D:\TEST_SOURCE\CV\SOURCE CODE\ARMY.Data\ProceduresALL
Path.GetDirectoryName(path);

//ProceduresALL
Path.GetDirectoryName(path).Split(Path.DirectorySeparatorChar).Last();

Use Path.Combine("ProceduresALL", "ISample.cs") to get ProceduresALL\ISample.cs (using the above to get these strings).

like image 200
BlueVoodoo Avatar answered Dec 02 '22 23:12

BlueVoodoo