How can I find full path for a file?

Let's say I have this path D:\something\something1\from_here_I_now\stuff\stuff2.

So, I know that \from_here_I_now\stuff\stuff2 is a permanent path, but the beginning is different, like I know that D:\something\something1\ may be different for someone else. How can I find the D:\something\something1\ knowing only \from_here_I_now\stuff\stuff2?

1 answer

  • answered 2021-01-19 21:37 Jan Willem

    Try something like this:

    import os
    filestr = '\from_here_I_now\stuff\stuff2'
    fullstr = os.path.abspath(filestr)
    >>> 'D:\something\something1\from_here_I_now\stuff\stuff2'
    >>> 'D:\something\something1'