如何拆分路径以获取Value CustomCompanyNames?
C:\Project\v4.0\Tool\Custom\CustomCompanyNames\Template\bin\file\file.xml
我如何获得价值?
答案 0 :(得分:2)
如果您想获取特定文件的“Template”目录的父目录,可以试试这个:
public string GetTemplateDirectoryParentName(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
DirectoryInfo directoryInfo = fileInfo.Directory;
while(directoryInfo.Name != "Tempalte")
{
direcotryInfo = direcotryInfo.Parent;
}
return direcotryInfo.Parent.Name;
}
您可以通过获取“自定义”目录的子目录来实现另一种方式:
public string GetTemplateDirectoryParentName(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
DirectoryInfo directoryInfo = fileInfo.Directory;
while(directoryInfo.Parent.Name != "Custom")
{
direcotryInfo = direcotryInfo.Parent;
}
return direcotryInfo.Name;
}