1

The exact same question has been asked, but I don't understand why I am not receiving the same output.

I've tested it using the same example below (without full path)

string path = @"C:\Folder1\Folder2\Folder3\Folder4";
string newPath = Path.Combine(path, @"..\..\");

Now from the original question that was asked. The answer was the result should be:

newPath = @"C:\Folder1\Folder2\";

However I am getting this:

newPath = @"C:\\Folder1\\Folder2\\Folder3\\Folder4/..\\..\\";

EDIT: Using the line below still did not accomplish what it was supposed to do.

Path.Combine(path, "..", "..");

output using above resulted below:

"C:\\Folder1\\Folder2\\Folder3\\Folder4/../.."
Que
  • 11
  • 2
  • 2
    Use `Path.Combine(path, "..", "..");` as explained in the comment https://stackoverflow.com/questions/14899422/how-to-navigate-a-few-folders-up#comment97806320_30902714. – Progman Feb 20 '21 at 23:52
  • @Progman Thanks for the response. I've used `Path.Combine(path, "..", "..");` and I've gotten: `"C:\\Folder1\\Folder2\\Folder3\\Folder4/../.."` as the value. – Que Feb 20 '21 at 23:58
  • @Progman which did not behave how it should. – Que Feb 21 '21 at 00:08
  • So what is wrong for it? This path points to a folder that you need. It will work for you. Or you need to output the path somewhere else in a handy format? – Ivan Khorin Feb 21 '21 at 00:10
  • @Progman Sorry, your solution was correct. It was my transition from Windows to Mac. I didn't realize there was a path difference. Appreciate your help! – Que Feb 21 '21 at 00:21

0 Answers0