os.path.exists 无法识别 C:\Windows\system32\drivers 下的子目录 [英] os.path.exists does not recognize a subdirectory under C:\Windows\system32\drivers
问题描述
谁能告诉我为什么会出现这种行为:
Can anyone tell me why this behaviour is exhibited:
C:\...>dir C:\Windows\System32\drivers\subdir\0xDEADBEEF.008
Volume in drive C is Win7HPx64
Volume Serial Number is 04BF-EE2E
Directory of C:\Windows\System32\drivers\subdir\0xDEADBEEF.008
08/11/2011 04:21 PM <DIR> .
08/11/2011 04:21 PM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 11,581,788,160 bytes free
C:\...>C:\Python27\python.exe
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> silo = r'C:\Windows\System32\drivers\subdir\0xDEADBEEF.008'
>>> os.path.isdir(silo)
False
>>> os.path.exists(silo)
False
os.stat
在所述目录上引发 WindowsError:[错误 3] 系统找不到指定的路径...."
os.stat
on said directory raises a WindowsError: "[Error 3] The system cannot find the path specified...."
我也尝试过使用以管理员身份运行"上下文菜单启动的 cmd 控制台.没有骰子:
I tried with a cmd console launched with "Run as administrator" context menu, too. No dice:
推荐答案
如果您在 64 位 Windows 上使用 32 位 Python 构建,那么对 C:\WINDOWS\SYSTEM32 的访问将被透明地重定向到 C:\WINDOWS\SYSWOW64.在 64 位系统上,SYSTEM32 包含 64 位 DLL,SYSWOW64 包含 32 位 DLL.
If you're using a 32-bit Python build on 64-bit Windows, then accesses to C:\WINDOWS\SYSTEM32 will be transparently redirected to C:\WINDOWS\SYSWOW64. On 64-bit systems, SYSTEM32 contains 64-bit DLLs and SYSWOW64 contains 32-bit DLLs.
要从 32 位 Python 访问真正的 SYSTEM32 目录,请使用 C:\WINDOWS\SYSNATIVE.
To access the real SYSTEM32 directory from a 32-bit Python, use C:\WINDOWS\SYSNATIVE.
http://msdn.microsoft.com/en-us/library/aa384187%28v=vs.85%29.aspx
这篇关于os.path.exists 无法识别 C:\Windows\system32\drivers 下的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!