9

There are many examples of resolving the path of a file while following symlinks, and I'd like to get the absolute path to a file without resolving symlinks. I think this is the solutions:

 ex=Path('example.txt') 
 abs_ex = ex.parent.resolve()/ex

Is there something I'm missing in terms of another function or argument to resolve()?

There is an answer regarding using os.path.abspath but I'm asking about pathlib in Python 3.6 or better.

8
  • could you elaborate on the not resolving symlinks part. A detailed answer to that would depend on OS an possibly the specific filesystem in use. Commented Mar 28, 2018 at 20:38
  • If this question is really about symlinks then it's not duplicate of the one above. If it's not really about symlinks then the link in the comments here would cover it. Commented Mar 28, 2018 at 20:39
  • 3
    As tagged this question is about the pathlib and is not a duplicate of the os.path.abspath() answer. Commented Mar 28, 2018 at 22:06
  • Sorry this question got marked dupe, I agree that it's not and put in into the re-open queue for re-review. thanks for your patience Ray :-) Commented Apr 2, 2018 at 18:39
  • 2
    @ArthurUlfeldt: The dupe target is OS-agnostic. The example merely happens to be a Windows path. The answer in the dupe target does not resolve symlinks, regardless of OS. (Also, Windows has symlinks.) Commented Mar 10, 2019 at 2:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.