[英]Checking whether %APPDATA% exists always returns false
I am trying to check whether my applications directory exists inside the %APPDATA% folder. 我正在尝试检查我的应用程序目录是否在%APPDATA%文件夹内。
My Problem: Using print os.path.exists("%APPDATA%")
, it always returns False which is obviously completely incorrect. 我的问题:使用
print os.path.exists("%APPDATA%")
,它总是返回False,这显然是完全不正确的。 Why is this happening and how can I fix it? 为什么会发生这种情况,我该如何解决?
You need expand environmental variables using os.path.expandvars : 您需要使用os.path.expandvars扩展环境变量:
>>> os.path.expandvars("%APPDATA%")
'C:\\Documents and Settings\\falsetru\\Application Data'
>>> os.path.exists(os.path.expandvars("%APPDATA%"))
True
Without expanding, "%APPDATA%"
means literally %APPDATA%
in current working directory. 如果不扩展,
"%APPDATA%"
表示当前工作目录中的%APPDATA%
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.