【发布时间】:2010-01-12 05:32:24
【问题描述】:
我在解析共享路径(服务器上的共享路径,例如 \storage\Builds)时看到一些奇怪的行为
我正在阅读包含我想要进一步处理的目录路径的文本文件。为此,我执行以下操作:
def toWin(path):
return path.replace("\\", "\\\\")
for line in open(fileName):
l = toWin(line).strip()
if os.path.isdir(l):
print l # os.listdir(l) etc..
这适用于本地目录,但不适用于共享系统上指定的路径。
e.g.
E:\Test -- works
\\StorageMachine\Test -- fails [internally converts to \\\\StorageMachine\\Test]
\\StorageMachine\Test\ -- fails [internally converts to \\\\StorageMachine\\Test\\]
但是,如果我打开 python shell,导入脚本并使用相同的路径字符串调用函数,那么它就可以工作了!
在这两种情况下,解析 Windows 共享路径的行为似乎有所不同。
有什么想法/建议吗?
【问题讨论】: