【发布时间】:2017-01-22 09:11:20
【问题描述】:
我正在尝试使用 os.path.isfile 测试网络驱动器上是否存在文件,但是即使文件存在,它也会返回 false。任何想法为什么会这样或我可以用来检查此文件的任何其他方法?
我使用的是Python2.7和Windows10
这将返回 true:
import os
if os.path.isfile("C:\test.txt"):
print "Is File"
else:
print "Is Not File"
即使文件存在,这也会返回 false:
import os
if os.path.isfile("Q:\test.txt"):
print "Is File"
else:
print "Is Not File"
【问题讨论】:
-
使用原始字符串:
os.path.isfile(r"Q:\test.txt")? -
也返回 false
-
os.path.exists()返回什么? -
os.path.exists() 也返回 false
标签: python python-2.7