7

I'm porting an application to Windows and I need to decide where to store user settings and session information on the filesystem. Under linux I put everything under ~/.myapp. I could do the same on Windows, but I'm wondering what the canonical approach is for this.

Things that will be stored in this directory:

  • user settings that need to persist across app lifetimes

  • user authentication information

  • logs

Alex Flint
  • 215
  • 1
  • 6
  • 1
    %AppData%myapp is the usual spot. There's some complexity depending on whether the user is attached to a domain and has Roaming enabled, but in my case it points to C:\Users\johnsmith\AppData\Roaming . Each user has a unique %AppData% folder that's only accessible under that user's login. There's also %TEMP% for per-app-lifetime data. I don't suggest putting logs or anything important in %TEMP% because some people like to run Disk Cleanup or similar utilities while other programs are still running. – Christopher Hostage Dec 13 '16 at 00:40
  • You should use %UserProfile% – answerSeeker Dec 13 '16 at 00:44
  • 1
    The document with the recommended locations, dating from the introduction of the current naming conventions with Vista, has disappeared from the Microsoft download site. However, a copy can be found here https://www.scribd.com/document/48246732/Windows-File-System-Namespace-Usage-Guidelines – David Marshall Dec 13 '16 at 00:50
  • http://superuser.com/questions/1048579/cmd-equivalent-to-cd-to-change-to-c-users-current-user-documents/ http://superuser.com/questions/476274/is-there-a-windows-equivalent-to-using-as-a-shorthand-symbolizing-your-home-u/ http://superuser.com/questions/332871/what-is-the-equivalent-of-linuxs-tilde-in-windows – random Dec 13 '16 at 05:38

1 Answers1

12

The %userprofile% variable is the closest thing to that. It'll expands to your user directory (c:\users\foo). This is probably not the canonical place

However I believe for this sort of thing %appdata% (which expands to %userprofile%\appdata\roaming)- which essentially is used for the sort of thing that dotfolders are used for or the registry would be more appropriate. This is used even if you're not actually on a domain or roaming.

You can find a full list of environmental variables here

Journeyman Geek
  • 127,463
  • 52
  • 260
  • 430