How can I get the path to the %APPDATA%
directory in Python?
If you want AppData\Roaming
import os
print(os.getenv('APPDATA'))
If you are looking for AppData\Local
, then use
import os
print(os.getenv('LOCALAPPDATA'))
For AppData\Local\Temp
you can get it in this way, which also makes your code portable accross platforms
import tempfile
print(tempfile.gettempdir())
For the differences:
Roaming is the folder that would be synchronized with a server if you logged into a domain with a roaming profile (enabling you to log into any computer in a domain and access your favorites, documents, etc. Firefox stores its information here, so you could even have the same bookmarks between computers with a roaming profile.
Local is the folder that is specific to that computer - any information here would not be synchronized with a server. This folder is equivalent in Windows XP to C:\Documents and Settings\User\Local Settings\Application Data.
See also this answer.