So apparently the Local AppData path is stored in the registry under \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData
But then the problem becomes that the paths can contain any environment variable (for example %USERPROFILE%) so now you need to resolve every one of those, make the string replacement, then cast it into a FolderItem. This is also complicated by the fact that something like “%USERPROFILE%” is both a possible environment variable or a valid folder name.
There has to be a simpler way as this seems as if it would be basic functionality.
It is documented by Microsoft that you should not rely on those values in the registry. Your approach reading the environment variable it probably the more reliable approach.
A better approach would be to use the Win32 API SHGetKnownFolderPath function with the corresponding KNOWNFOLDERID using a declare in Xojo.
Const CSIDL_LOCAL_APPDATA = &h1c
Declare Function SHGetSpecialFolderPathA Lib "Shell32" (hwnd As Integer, pszPath As Ptr, csidl As Integer, fCreate As Boolean) As Boolean
Var oSpace As New MemoryBlock(1024)
Var pSpacePtr As Ptr = oSpace
If SHGetSpecialFolderPathA(0, pSpacePtr, CSIDL_LOCAL_APPDATA, False) Then
Var sPath As String
sPath = oSpace.CString(0)
Return New FolderItem(sPath, FolderItem.PathModes.Native)
End If
@Stefan_Roth1 Thank you for that! I believe you are correct that this is the “correct” way to retrieve it. @Rick_Araujo’s workaround is absolutely brilliant too, after a bit of research it turns out that the Temporary folder is always part of the local Appdata.
@Michel_Bujardet I am interfacing with another piece of software that writes its configuration file to a subfolder of LocalAppData.
Ask Stefan to rewrite that solution using the current SHGetKnownFolderPath instead of the legacy SHGetSpecialFolderPathA so it can be safer/proper for international users with unicode string paths.
That’s why I opted for using the shorter Xojo native option.