Is there a short way to get certain parent directory path from current path.
I have a path like this:
"c:\\users\\userName\\documents\\visual studio 2013\\Projects\\SolutionName\\ProjectName\\bin\\Debug"
and i want to get the path to 'SolutionName' directory, like this
"c:\\users\\userName\\documents\\visual studio 2013\\Projects\\SolutionName"
I need it because i am storing some data in folder
"c:\\users\\userName\\documents\\visual studio 2013\\Projects\\SolutionName\\DataFolder"
and i need to access it from different projects in my solution.
Thank you all, there is what i finished with
public static string GetParent( string parentName,string FileName)
{
var dir = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
while (dir.Parent.Name != parentName)
{
dir = dir.Parent;
}
return dir.Parent.FullName+"\\Data\\"+FileName;
}
I accepted Callum Bradbury answer because i just changed it not to be recursive.