我们可以从C#中的最后一个文件夹中分割文件路径吗? [英] Can we split the Filepath from the last folder in C#?

查看:244
本文介绍了我们可以从C#中的最后一个文件夹中分割文件路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个文件ISample.cs在这个路径像

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

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

这里我想file-path from

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.

请帮助我。

推荐答案

您的意思是这样吗?

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();

使用Path.Combine(ProceduresALL,ISample.cs)获取ProceduresALL \ISample .cs(使用上面的方法获取这些字符串)。

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

这篇关于我们可以从C#中的最后一个文件夹中分割文件路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆