C#获取上级文件夹路径
/// <summary> /// 获取上级文件夹路径 /// </summary> /// <param name="path">路径</param> /// <param name="degree">级数</param> /// <returns></returns> private string GetParentDirectory(string path, int degree) { DirectoryInfo pathInfo = new DirectoryInfo(path); string newPath = pathInfo.Parent.FullName; for (int i = 0; i < degree; i++) { pathInfo = new DirectoryInfo(newPath); newPath = pathInfo.Parent.FullName; } return newPath; }