最佳答案
我需要得到工作目录的最后一部分,例如从 /Users/smcho/filegen_from_directory/AIRPassthrough
,我需要得到 AIRPassthrough
。
使用 python,我可以用这个代码得到它。
import os.path
path = "/Users/smcho/filegen_from_directory/AIRPassthrough"
print os.path.split(path)[-1]
或者
print os.path.basename(path)
我怎么能对 C # 做同样的事情呢?
在答案的帮助下,我找到了我需要的。
using System.Linq;
string fullPath = Path.GetFullPath(fullPath).TrimEnd(Path.DirectorySeparatorChar);
string projectName = fullPath.Split(Path.DirectorySeparatorChar).Last();
或者
string fullPath = Path.GetFullPath(fullPath).TrimEnd(Path.DirectorySeparatorChar);
string projectName = Path.GetFileName(fullPath);