Ver*_*ric 14 python python-3.x
我有一个关于在Windows上显示来自网络驱动器的文件的问题.
path = "\\\\nexus\\File Server\\Technical\\MyDrive\\Software\\Releases\\%s\\%s\\" %(release, module)
哪里\\nexus\是网络驱动器.
我的主要问题是用户输入正确的变量,我无法显示所请求目录的内容("模块"的内容).
os.listdir(path)
上面一行的问题是它返回一个Windows错误[123],这是一个找不到目录错误.这是因为listdir()似乎将所有反斜杠加倍,导致:
"\\\\\\\\nexus\\File Server\\\\Technical\\\\MyDrive\\\\Software\\\\Releases\\\\release\\\\module\\\\"
print(glob.glob(path))
我真的不确切知道它是如何工作的:P但它似乎只是显示提供的目录而不是结束目录的内容
 \\nexus\File Server\Technical\MyDrive\Software\Releases\release\module\"
我已经看到了os.walk但是我不确定它是如何工作的,因为它如何定义什么是基本目录/目录以及路径的其余部分是什么
额外注意事项:'module'的内容将始终为zip文件,目录通常最多包含5个zip文件.
Ale*_*x L 16
刚刚在我的XP PC,Python 2.7,SMB共享上测试过 \\myshare
os.listdir('\\\\myshare') # Fails with "WindowsError: [Error 53] The network path was not found"
os.listdir('\\\\myshare/folder') # Succeeds
我认为一些混乱可能是由WindowsError显示repr()路径而不是实际路径引起的 -
>>> repr(path)
"'\\\\myshare'"
>>> str(path)
'\\myshare'
如果这是Python 3和unicode问题,我建议先尝试修复字符串:
path = "\\\\myshare\folder"
path = bytes(path, "utf-8").decode("unicode_escape")
print os.listdir(path)
(遗憾的是我无法测试这个,因为我没有安装Python 3,但请告诉我它是否有效,我会编辑我的答案)
小智 5
这对我有用:
os.listdir('\\\\server\folder\subfolder\etc')
(在 Win7 64b 上使用 Python 2.7 32b)
| 归档时间: | 
 | 
| 查看次数: | 40189 次 | 
| 最近记录: |