获取n级父目录名称

Posted on 2015-06-08 14:35  云起  阅读(6)  评论(0)    收藏  举报  来源
DirectoryInfo GetPrant(DirectoryInfo path, int level)
{
    DirectoryInfo temp = null;

    if (level > 1)
    {
        level--;
        temp = GetPrant(path.Parent, level);
    }
    else
        temp = path;
    return (temp);
}


调用

int LEVEL = 10;
string NAME =  GetPrant(Directory.GetParent(FullPath), LEVEL ).Name;

LEVEL 为父目录级别,1为本身;FullPath为全路径,通过路径过去对应目录

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3