【问题标题】:os.path.exists does not recognize a subdirectory under C:\Windows\system32\driversos.path.exists 无法识别 C:\Windows\system32\drivers 下的子目录
【发布时间】:2011-08-12 00:30:24
【问题描述】:

谁能告诉我为什么会出现这种行为:

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]系统找不到指定的路径....”

我也尝试使用“以管理员身份运行”上下文菜单启动的 cmd 控制台。没有骰子:

【问题讨论】:

  • 你确定它还存在吗?
  • 是的。我复制粘贴了所有内容(不仅是上面的屏幕,还包括资源管理器地址栏中的路径名)。
  • 如果 Python 没有以管理员身份运行,它是否能够查看 `C:\Windows\System32`?
  • 我也尝试过使用“以管理员身份运行”上下文菜单启动的 cmd 控制台。没有骰子。 :-(
  • 我无法在 Windows 7、Python 2.7 和以管理员身份运行时重现此问题。在没有管理员提示的情况下没有尝试过,因为我必须先重新启用 UAC。

标签: python windows


【解决方案1】:

如果您在 64 位 Windows 上使用 32 位 Python 构建,则对 C:\WINDOWS\SYSTEM32 的访问将透明地重定向到 C:\WINDOWS\SYSWOW64。在 64 位系统上,SYSTEM32 包含 64 位 DLL,SYSWOW64 包含 32 位 DLL。

要从 32 位 Python 访问真正的 SYSTEM32 目录,请使用 C:\WINDOWS\SYSNATIVE。

http://msdn.microsoft.com/en-us/library/aa384187%28v=vs.85%29.aspx

【讨论】:

  • 当我没有在 XP 32 位机器上重现它时,我只是有了这个顿悟,而你刚刚确认了它!谢谢!
猜你喜欢
  • 2013-01-25
  • 2022-09-29
  • 2019-05-08
  • 2019-09-09
  • 1970-01-01
  • 2019-12-18
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
相关资源
最近更新 更多