os.path.isfile返回false

时间:2017-12-19 04:29:17

标签: python python-3.x

我一直在浏览,并且在这种情况下,os.path.isfile()不断返回false的原因很难说明。

if os.path.isfile(os.path.join(rootDir, file)):
     print("hit")
else:
     print(os.path.join(rootDir, file))
     print("else")

在{else}块中打印时,os.path.join(rootDir, file)生成的两个变量的格式为:./rootDir/file1./rootDir/file2

你知道,每个文件都应该在rootDir中从一个子目录进行比较,然后才能被移动到rootDir中;然而,它只是抓住了其他声明。如果该文件存在,则将其作为' ./ rootDir / file1'和一个' ./ rootDir / sub / file2',然后结果应该是一个命中,另一个打印。

因为确实存在于该目录中的文件中(如print(os.path.join(rootDir,file))语句所示),我不明白为什么两者都在击中else(false)

PS。两个文件都是.pptx文件只是重要的事情

0 个答案:

没有答案
相关问题