python os.path.exists()可以';找不到该文件,但该文件确实存在

python os.path.exists()可以';找不到该文件,但该文件确实存在,python,Python,这是我的代码,它可以找到文件ctfmon.exe,但找不到文件cc.dll >>> import os >>> os.path.exists("c:\\windows\\system32\\ctfmon.exe") True >>> os.path.exists("c:\\windows\\system32\\cc.dll") False 但是文件cc.dll确实存在 C:\Windows\System32&g

这是我的代码,它可以找到文件
ctfmon.exe
,但找不到文件
cc.dll

   >>> import os
   >>> os.path.exists("c:\\windows\\system32\\ctfmon.exe")
   True
   >>> os.path.exists("c:\\windows\\system32\\cc.dll")
   False
但是文件
cc.dll
确实存在

C:\Windows\System32>dir cc.dll
 驱动器 C 中的卷没有标签。
 卷的序列号是 B481-54FB

 C:\Windows\System32 的目录

2014/04/17  14:12                 0 cc.dll
           1 个文件              0 字节
           0 个目录  8,659,787,776 可用字节
试试这个例子:

os.path.isfile("your address/your file")
它来自python文档

os.path.exists(路径)
如果路径引用现有路径,则返回True。对于断开的符号链接,返回False。在某些平台上,如果未授予对请求文件执行
os.stat()
的权限,则此函数可能返回False,即使路径实际存在。

这可能是您的问题。

尝试删除双斜杠

import os
print os.path.exists("c:\\windows\system32\cca.dll")


您正在64位版本的Windows上运行32位版本的python。在64位Windows中启动32位应用程序时,C:\Windows\SysWOW64将映射到C:\Windows\System32

windows不区分大小写吗?导入os print os.path.exists(“c:\\windows\system32\cca.dll”)是显示零字节文件的cc.dll目录吗?请尝试使用os.listdir()列出“c:\\windows\\system32\\”的所有文件,可能它会以不同的名称出现,或者您的程序没有写入来查看file@TimCastelijns不,不是。从那以后,这就不起作用了。你有iterable
c
\`,
windows`
ystem32
等等。然后你要么做了
r“c:\windows\system32\cca.dll”
或者您确实使用了
“C:/Windows/system32/cca.dll”
打印os.path.exists(““C:\Windows\system32\cc.dll”)。这同样有效。最好的方法是使用
os.path.join('C:\\'、'Windows'、'system32'、'cca.dll')
,您是对的,在该示例中它是有效的,因为
\w
\s
,,
\c
是转义字符。天堂禁止您查找
“C:\windows\system32\nslookup.exe”
尽管:)谢谢您的帮助。但我刚刚尝试了os.path.isfile。它仍然返回false。当我尝试同一目录中的其他dll文件时,成功了。@marsen我确信
os.path.isfile
extensions
os.path.exists
在某种程度上是存在的:)这很难确定test@maersen用os.path.getsize(path)@marsen检查目录的大小,以确定python是否可以识别该dll文件。检查这个问题()我已经尝试过大小,没有相同大小的文件。但是我发现一个可疑文件,它的名称相似,但大小不同。我在CMD中找不到文件。这是正确答案,应该接受。使用
ctypes
Wow64DisableWow64FsRedirection
禁用此映射()
print os.path.exists("""c:\\windows\system32\cca.dll""")