views:

56

answers:

3

Not completely a programming question, but its close enough so here goes:

In Mac OS I'll put user-specific files for my app in ~/Library/Application Data/{MyApp}/ and in *nix I'll put them in ~/.{MyApp}/ - where should I put them for Windows?

I'll be using Ruby's File.expand_path to get to this directory, so if there's a windows equivalent of ~ then that's fine.

(Answers for Windows XP, Vista and 7 would be appreciated if they're not the same)

A: 

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.

Jerry Coffin
One nit, but SHGetSpecialFolderPath is deprecated in favor of ShGetFolderPath (http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx).
Larry Osterman
@Larry:Good point -- I should have mentioned that. Thanks for adding it.
Jerry Coffin
A: 

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 enviroment 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.

miket2e
Just please don't hard code the paths that miket2e listed - instead use Environment.SpecialFolder.ApplicationData for .net apps or ShGetFolderPath(NULL, CSIDL_APPDATA, NULL, ...) for native windows apps.
Larry Osterman
And in Ruby? At the moment I'd have to hard-code ~/AppData/MyApp as I know of no way to the application data folder in Ruby!
JP
A: 

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.

AndrewD