Windows Application Data Directory Windows Application Data Directory windows windows

Windows Application Data Directory


The way the do this on Windows is to use the ApplicationData environment variable. If you were using C# you can get the folder it maps to using System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), googling for the Ruby equivalent it's ENV['APPDATA']. In English-language Windows it maps to:

C:\Users\%username%\AppData\Roaming\ (on Vista and Windows 7)

C:\Documents and Settings\%username%\Application Data\ (On XP)

It may map to a different folder in other languages, but as long as you get the directory from the environment variable and not hard-code it then it doesn't really make a difference. If you create a folder in there for your app and store the data there, Vista and 7 will allow read and write access to it without giving UAC prompts.


Offhand, I'm not sure how Ruby handles expand_path on ~ for Windows. Windows has functions like SHGetSpecialFolderPath, and SHGetSpecialFolderLocation for this kind of thing. It would seem like an obvious thing for expand_path to use one of those, but I don't know whether it does for sure.


For Vista and Windows 7 and Windows XP,

    char appdir[MAX_PATH];          size_t requiredSize;    errno_t err= getenv_s( &requiredSize, appdir, MAX_PATH, "appdata" );

seems simpler than using deprecated APIs or ones that don't work on Windows XP.