简体   繁体   English

subst ( O:\\ ) 文件夹的 python getcwd

[英]python getcwd of a subst ( O:\ )folder

I am running a python script from a subst folder in windows:我正在从 Windows 中的 subst 文件夹运行 python 脚本:

c:\MyFolder\Tmp\Code\subst O: .
O:\script.py

script.py is running the getcwd (and abspath ) command and it needs the real folder name, but instead it shows O:. script.py 正在运行getcwd (和abspath )命令,它需要真正的文件夹名称,但它显示的是 O:。

Is there a way to get the real folder name (without running the subst command and iterating the drives) and use an getcwd alternative?有没有办法获取真正的文件夹名称(无需运行subst命令并迭代驱动器)并使用getcwd替代方法?

As marking comments as accepted answer is impossible, I will quote @eryksun's comments:由于不可能将评论标记为已接受的答案,我将引用@eryksun 的评论:

The native path of the working directory will be something like "\\Device\\HarddiskVolume2\\MyFolder\\Tmp\\Code".工作目录的本机路径类似于“\\Device\\HarddiskVolume2\\MyFolder\\Tmp\\Code”。 If you open a handle to this directory via the subst drive "O:" and call GetFinalPathNameByHandle, Windows can reconstruct either the Volume GUID path or the DOS path.如果您通过子驱动器“O:”打开此目录的句柄并调用 GetFinalPathNameByHandle,Windows 可以重建卷 GUID 路径或 DOS 路径。 It gets the native device and file path via NtQueryObject and NtQueryInformationFile.它通过 NtQueryObject 和 NtQueryInformationFile 获取本机设备和文件路径。 Then it opens the mount-point manager "\\Device\\MountPointManager" to query the mapping from the native device path to either the "Volume{GUID}" name or the DOS logical drive letter (or folder if there is no drive letter mount)然后它打开挂载点管理器“\\Device\\MountPointManager”来查询从本机设备路径到“Volume{GUID}”名称或DOS逻辑驱动器盘符(如果没有驱动器盘符挂载则是文件夹)的映射

In Python 3, GetFinalPathNameByHandle is wrapped as os.path._getfinalpathname (only for getting the final DOS path).在 Python 3 中,GetFinalPathNameByHandle 被包装为 os.path._getfinalpathname(仅用于获取最终的 DOS 路径)。 It's used by pathlib.Path.resolve它由 pathlib.Path.resolve 使用

Much appreciated, thanks.非常感谢,谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM