osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

preferences file


On 1/24/19, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Thu, 24 Jan 2019 14:42:59 -0500, Dave <dboland9 at offilive.com> declaimed
> the following:
>>
>>3. File location?  I'm using Ubuntu and I believe that the correct
>>location would be home/.config/<app-name> .  What about Mac and Windows?
>>
> 	Windows?
>
> 			%UserProfile%\Roaming\<application>

That should be "%UserProfile%\AppData\Roaming". This is the default
path, which should never be used directly because "Roaming" is
relocatable. Use "%AppData%" instead.

That said, relying on environment variables isn't the best practice.
The value might be wrong if the folder was relocated after our process
tree was created. Use the shell's well-known-folder interface instead.
For example:

    import pythoncom
    from win32com.shell import shell

    kfmgr = pythoncom.CoCreateInstance(
                shell.CLSID_KnownFolderManager, None,
                pythoncom.CLSCTX_INPROC_SERVER,
                shell.IID_IKnownFolderManager)

    appdata = kfmgr.GetFolder(shell.FOLDERID_RoamingAppData)
    appdata_path = appdata.GetPath()

IKnownFolderManager interface:
https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-iknownfoldermanager

IKnownFolder interface:
https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-iknownfolder