This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.realpath on windows and substed drives
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: ntpath.realpath() should use GetFinalPathNameByHandle()
View: 14094
Assigned To: Nosy List: Totte Karlsson, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2019-02-25 23:21 by Totte Karlsson, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg336574 - (view) Author: Totte Karlsson (Totte Karlsson) Date: 2019-02-25 23:21
Python's os.path.realpath, when used with a substed drive on the Windows platform, don't resolve the substed path to the *real* path. 

For example creating a substed drive like this:

    subst z: C:\Users\Public\Desktop

and checking for the real path in python like this:

    import os
    myPath = "S:\\"
    print("Real path of: " + myPath + " is: " + os.path.realpath(myPath) )

prints

    Real path of: S:\ is: S:\

In the docs for the [subst][1] command, a substed drive is referred to as a *virtual* drive. Virtual, suggesting something being "not real", indicates that the Python *realpath* command is not working properly on Windows. 


  [1]: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst
msg336597 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-02-26 02:32
In Windows, realpath is currently an alias for abspath. Issue 14094 has a pending PR that implements realpath, but it's waiting on improved tests and final approval. I'm afraid it won't make it into 3.8.

I suggest using the resolve() method of a pathlib.Path. For example:

    >>> os.system('subst W: C:\\Windows')
    0
    >>> pathlib.Path('W:\\').resolve()
    WindowsPath('C:/Windows')
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80293
2019-02-26 02:32:10eryksunsetstatus: open -> closed

superseder: ntpath.realpath() should use GetFinalPathNameByHandle()

nosy: + eryksun
messages: + msg336597
resolution: duplicate
stage: resolved
2019-02-25 23:21:50Totte Karlssoncreate