/// <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; }