How can I find the path of a parent directory with a particular name? For instance, say I have directory
/a/b/c/d/e/f/g and I want to find the parent directory with name
c, I would want this to return
The use case is that I'm within a fairly nested directory structure, and I don't want to have to have the difficult to read string of
../../.., which I would also need to make sure to change when I updated the nesting level of the directory structure in the future.
Not a dealbreaker, but if there were two ancestor directories with the given name, I would ideally want the one with the longest path. i.e.
/a/b/c/d/e/c/f/g should ideally return
/a/b/c/d/e/c instead of