I have looked on Stack Overflow everywhere but I cant find a solution to this problem.
Given that I have a folder/file as string: "/path1/path2/path3/file"
how can I get the parent folder and its parent folder. In other words if I want to traverse up one level "/path1/path2/path3"
or two levels "/path1/path2"
how can I get those string values from the original string path in python?
Please note that I don't simply want the pieces of the path (in other words not a list of ['path1', 'path2', 'path3']
) but instead "/path1/path2/path3"
.