python 2 : Get network share path from drive letter

标签 python python-2.7 unc network-share

如果我使用以下命令获取所有已连接驱动器的列表:

available_drives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]

如何获取已连接驱动器的 UNC 路径?

os.path 只返回 z:\ 而不是 \share\that\was\mapped\to\z

最佳答案

使用win32wnet从 pywin32 转换你的驱动器号。例如:

import win32wnet
import sys

print(win32wnet.WNetGetUniversalName(sys.argv[1], 1))

当我运行它时,它给了我这样的东西:

C:\test>python get_unc.py i:\some\path
\\machine\test_share\some\path

关于 python 2 : Get network share path from drive letter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44970700/

相关文章:

c# - UNC 共享目录不存在

python - 如何通过Python 3.5将base64图像嵌入到HTML电子邮件中?

python - 将输入从一个 Dash DataTable 输入到第二个 Dash DataTable

将共享本地路径转换为 ​​UNC 路径的 VB.NET 代码

cmd - Jenkins 下 Gradle 和 UNC 路径的问题

Python静态变量生成器函数

python - Keras:如何获得预测类的置信度?

python - 如何检测图像中小于或大于 90 度的边缘(线)

python - 有 Pandas 解决方案吗? : with numba, 或 Cython - 到 `transform`/`apply` 带有索引,MultiIndexed DataFrame?

python - 如何在Python中从字典中打印2个或更多随机键