本文整理汇总了Python中win32com.shell.shellcon.CSIDL_APPDATA属性的典型用法代码示例。如果您正苦于以下问题:Python shellcon.CSIDL_APPDATA属性的具体用法?Python shellcon.CSIDL_APPDATA怎么用?Python shellcon.CSIDL_APPDATA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类win32com.shell.shellcon
的用法示例。
在下文中一共展示了shellcon.CSIDL_APPDATA属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: win32_appdata
# 需要导入模块: from win32com.shell import shellcon [as 别名]
# 或者: from win32com.shell.shellcon import CSIDL_APPDATA [as 别名]
def win32_appdata():
# try to use win32 api to get the AppData folder since python doesn't populate os.environ with unicode strings.
try:
import win32com.client
objShell = win32com.client.Dispatch("WScript.Shell")
return objShell.SpecialFolders("AppData")
except Exception, e:
print "Error while getting AppData folder using WScript.Shell.SpecialFolders: {0!r}".format(e)
try:
from win32com.shell import shell, shellcon
return shell.SHGetPathFromIDListEx(
shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA)
)
except Exception, e:
print "Error while getting AppData folder using SHGetSpecialFolderLocation: {0!r}".format(e)
return os.environ['APPDATA'].decode(sys.getfilesystemencoding())
示例2: win32_appdata
# 需要导入模块: from win32com.shell import shellcon [as 别名]
# 或者: from win32com.shell.shellcon import CSIDL_APPDATA [as 别名]
def win32_appdata():
# try to use win32 api to get the AppData folder since python doesn't populate os.environ with unicode strings.
try:
import win32com.client
objShell = win32com.client.Dispatch("WScript.Shell")
return objShell.SpecialFolders("AppData")
except Exception as e:
print "Error while getting AppData folder using WScript.Shell.SpecialFolders: {0!r}".format(e)
try:
from win32com.shell import shell, shellcon
return shell.SHGetPathFromIDListEx(
shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA)
)
except Exception as e:
print "Error while getting AppData folder using SHGetSpecialFolderLocation: {0!r}".format(e)
return os.environ['APPDATA'].decode(sys.getfilesystemencoding())
示例3: get_data_location
# 需要导入模块: from win32com.shell import shellcon [as 别名]
# 或者: from win32com.shell.shellcon import CSIDL_APPDATA [as 别名]
def get_data_location():
data_dir = None
if is_windows():
data_location = os.getenv('APPDATA')
if not os.path.exists(data_location):
try:
from win32com.shell import shellcon, shell
data_location = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
except ImportError: # quick semi-nasty fallback for non-windows/win32com case
data_location = os.path.expanduser("~")
data_dir = os.path.join(data_location, constant.APP_NAME)
if not os.path.exists(data_dir):
os.mkdir(data_dir)
if is_linux() or is_darwin():
home = path_translate("~")
data_dir = os.path.join(home, ".{}".format(constant.APP_NAME))
if not os.path.exists(data_dir):
os.mkdir(data_dir)
return data_dir
示例4: appdatadirectory
# 需要导入模块: from win32com.shell import shellcon [as 别名]
# 或者: from win32com.shell.shellcon import CSIDL_APPDATA [as 别名]
def appdatadirectory( ):
"""Attempt to retrieve the current user's app-data directory
This is the location where application-specific
files should be stored. On *nix systems, this will
be the ${HOME}/.config directory. On Win32 systems, it will be
the "Application Data" directory. Note that for
Win32 systems it is normal to create a sub-directory
for storing data in the Application Data directory.
"""
if shell:
# on Win32 and have Win32all extensions, best-case
return shell_getShellFolder(shellcon.CSIDL_APPDATA)
if _winreg:
# on Win32, but no Win32 shell com available, this uses
# a direct registry access, likely to fail on Win98/Me
return _winreg_getShellFolder( 'AppData' )
# okay, what if for some reason _winreg is missing? would we want to allow ctypes?
## default case, look for name in environ...
for name in ['APPDATA', 'HOME']:
if name in os.environ:
return os.path.join( os.environ[name], '.config' )
# well, someone's being naughty, see if we can get ~ to expand to a directory...
possible = os.path.abspath(os.path.expanduser( '~/.config' ))
if os.path.exists( possible ):
return possible
raise OSError( """Unable to determine user's application-data directory, no ${HOME} or ${APPDATA} in environment""" )
示例5: _get_nnabla_config
# 需要导入模块: from win32com.shell import shellcon [as 别名]
# 或者: from win32com.shell.shellcon import CSIDL_APPDATA [as 别名]
def _get_nnabla_config():
config_files = []
config_files.append(join(dirname(abspath(__file__)), 'nnabla.conf'))
if os.name == 'posix':
config_files.append('/etc/nnabla.conf')
config_files.append(abspath(join(expanduser('~'), '.nnabla')))
config_files.append(abspath(join(os.getcwd(), 'nnabla.conf')))
elif os.name == 'nt':
from win32com.shell import shell, shellcon
config_files.append(abspath(join(shell.SHGetFolderPath(
0, shellcon.CSIDL_COMMON_APPDATA, None, 0), 'NNabla', 'nnabla.ini')))
config_files.append(abspath(join(shell.SHGetFolderPath(
0, shellcon.CSIDL_APPDATA, None, 0), 'NNabla', 'nnabla.ini')))
config_files.append(abspath(join(os.getcwd(), 'nnabla.conf')))
if "NNABLA_CONFIG_FILE_PATH" in os.environ:
conf = os.environ["NNABLA_CONFIG_FILE_PATH"]
if os.path.exists(conf):
config_files.append(conf)
config = configparser.RawConfigParser()
for filename in config_files:
# print(' Checking {}'.format(filename))
if exists(filename):
# print(' Read from {}'.format(filename))
config.read(filename)
return config
示例6: get_config_dir
# 需要导入模块: from win32com.shell import shellcon [as 别名]
# 或者: from win32com.shell.shellcon import CSIDL_APPDATA [as 别名]
def get_config_dir():
"""a cross-platform way to get user's config directory.
"""
if _config_dir is not None:
return _config_dir
shellvars = ['${APPDATA}', '${HOME}', '${USERPROFILE}']
dir_root = get_dir_root(shellvars)
if dir_root is None and os.name == 'nt':
app_dir = get_shell_dir(shellcon.CSIDL_APPDATA)
if app_dir is not None:
dir_root = app_dir
if dir_root is None and os.name == 'nt':
tmp_dir_root = os.path.split(sys.executable)[0]
if os.access(tmp_dir_root, os.R_OK|os.W_OK):
dir_root = tmp_dir_root
return dir_root
# For string literal subdirectories, starting with unicode and then
# converting to filesystem encoding may not always be necessary, but it seems
# safer to do so. --Dave