如果我使用以下命令获取所有已连接驱动器的列表:
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/