Python 2:从驱动器号获取网络共享路径 [英] Python 2: Get network share path from drive letter

查看:264
本文介绍了Python 2:从驱动器号获取网络共享路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I use the following to get the list of all connected drives:

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

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

How do I get the UNC path of the connected drives?

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

推荐答案

使用 win32wnet 从pywin32转换您的驱动器号.例如:

Use win32wnet from pywin32 to convert your drive letters. For example:

import win32wnet
import sys

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

当我运行它时,它给了我类似的东西:

This gives me something like this when I run it:

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

这篇关于Python 2:从驱动器号获取网络共享路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆