gpt4 book ai didi

windows - subst 的 python getcwd ( O :\)folder

转载 作者:可可西里 更新时间:2023-11-01 10:42:13 25 4
gpt4 key购买 nike

我在 Windows 的 subst 文件夹中运行 python 脚本:

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

script.py 正在运行 getcwd(和 abspath)命令,它需要真实的文件夹名称,而是显示 O:。

有没有办法获取真实的文件夹名称(无需运行 subst 命令和迭代驱动器)并使用 getcwd 替代方案?

最佳答案

由于无法将评论标记为已接受的答案,我将引用@eryksun 的评论:

The native path of the working directory will be something like "\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. It gets the native device and file path via NtQueryObject and 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)

In Python 3, GetFinalPathNameByHandle is wrapped as os.path._getfinalpathname (only for getting the final DOS path). It's used by pathlib.Path.resolve

非常感谢,谢谢。

关于windows - subst 的 python getcwd ( O :\)folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46998658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com