# In which directory to write game save files/data?

I need a definite list of directories, one or more per platform, of where to put game save files and other game generated data. Either based on the OS developer specification, or because it is common usage if there is no recommendation.

Please provide one answer per platform, with different directories. Also, example of how to get the directory location in C++ or C is best, as it's the language you'll have more hard time.

Locations:

• Player's game data (saved games, config).
• Shared game data (like high-score or config for all computer users).
• Temporary game data (aka cache directory).
• You should probably put all answers into one, since there isn't a single answer to accept? – Zolomon Sep 8 '12 at 10:29
• @Zolomon The problem is that one answer with all the platforms will be too big I think. In particular if you add mobile/tablet platforms... – Klaim Sep 8 '12 at 10:51
• it may be worth noting (since there may be more who share this opinion) that at least I hate when games doesn't save into their respectful (install) directories. I like games where in-game users are created in-game, and no more hiding is necessary: the PCs I use for gaming are never multi-user enough to use the OS users at all. Or if it must use it, I like games that do it internally. May be not the case, but: the idea of one OS user = one piece of game user alterego is also distressing. note I'm a windows gamer. on *unix it's different, the fixed FS forces the concept (there are no drives) – n611x007 Sep 8 '12 at 13:17
• @naxa If that can "consolate" you, I'm making a game that have a players account management inside, but players account still have to be stored in user's account for OS security reasons. I might store them in shared repo too, not sure. Also, I'll need to allow users to keep data online at some point. – Klaim Sep 8 '12 at 22:19
• @naxa The problem is that on Vista, Windows7, Windows8, unless specifically run as administrator, the programs wont be able to write to Program Files\Game-Install-Dir\. I believe this holds true on more recent Linux and OSX versions too. – Nate Sep 9 '12 at 0:39

# Windows (Xp and following)

Based on:

These locations assume that Windows is installed on the C: disk. Append your own directory with game name or game company then game name to these directories.

If you use Window 8 Metro-style application, you'll have to use a specific API instead of trying to reach directories. Read:

## Player's game data

Windows Vista and following:

C:\Users\{username}\AppData\Roaming

Windows Xp:

C:\Documents and Settings\{username}\Application Data

You can automatically get the right user-name-dependant address by getting the APPDATA environment variable.

Standard C (all compilers):

char* appdata = getenv("APPDATA");


Visual Studio 20xx (avoid getenv() warning saying it's not safe) - non Metro Style:

char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "APPDATA" );


Boost users: at the moment I write this boost.filesystem (that is also a draft of the filesystem library proposed to the next C++ standard) doesn't implement yet a function to provide the right directory. However, there have been discussions about this before. Please feel free to update this section if things changed.

## Shared game data

Windows Vista and following:

C:\ProgramData

Windows Xp:

C:\Documents and Settings\All Users

You can automatically get the right address by getting the PROGRAMDATA environment variable.

Standard C (all compilers):

char* appdata = getenv("PROGRAMDATA");


Visual Studio 20xx (avoid getenv() warning saying it's not safe) - non Metro Style:

char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "PROGRAMDATA" );


Boost users: at the moment I write this boost.filesystem (that is also a draft of the filesystem library proposed to the next C++ standard) doesn't implement yet a function to provide the right directory. However, there have been discussions about this before. Please feel free to update this section if things changed.

## Temporary game data

Windows Vista and following:

C:\ProgramData

Windows Xp:

C:\Documents and Settings\{username}\Local Settings\Temp

You can automatically get the right address by getting the TEMP environment variable.

C++ Boost users: there is a simple cross-platform boost.filesystem function for this

namespace bfs = boost::filesystem;
const bfs::path TEMP_DIR = bfs::system_complete( bfs::temp_directory_path() ); // system_complete() call is optional


Standard C (all compilers):

char* appdata = getenv("TEMP");


Visual Studio 20xx (avoid getenv() warning saying it's not safe) - non Metro Style:

char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "TEMP" );

• On Vista and up, game saves should preferable be placed in the special "Saved games" folder. More info here: msdn.microsoft.com/en-us/library/windows/desktop/… Look for "FOLDERID_SavedGames" – Durza007 Sep 8 '12 at 10:51
• You should never be trying to guess the path yourself or construct it from environment variables, really. On Vista and above, you should call SHGetKnownFolderPath (msdn.microsoft.com/en-us/library/bb762188.aspx) and on XP and below use SHGetFolderPath (msdn.microsoft.com/en-us/library/bb762181.aspx) – Kylotan Sep 8 '12 at 12:01
• @Kylotan and Durza007, I'm a bit short on time, feel free to edit this answer as necessary. Made this answer community wiki. – Klaim Sep 8 '12 at 12:34
• I think it's important to say that the msdn documentation suggests using SHGetKnownFolderPath since SHGetFolderPath is just a wrapper for the new method and is only supported for backward compatibility. – Kagemusha Nov 15 '12 at 12:29

# MacOS

Based on:

In unix-based OS, the ~ directory is automatically located at the user's home directory where user-specific data are located. This means that whatever the language, on these platforms you can access automatically this folder by using ~ instead of using a OS-specific function. Also note that / is the root path of the whole system, not a path to the root of the main disk.

Append your own directory with game name or game company then game name to these directories.

## Player's game data

Apple's guideline is to locate save and config files there to make them saved automatically in the cloud if available:

~/Documents

However, it is better (and more often used) practice to locate these files in:

~/Library/Application Support/

Just know that in this case the files will not be saved automatically to the cloud. If you want the player to choose, use the platform's API to make him choose.

## Shared game data

/Library/Application Support

Notice that there is no ~, it's not relative to user's home but to system's root.

## Temporary game data:

If the data don't need to be kept between executions:

/tmp

If the data need to be kept between executions;

/Library/Caches (for MacOSX)

C++ Boost users: there is a simple cross-platform boost.filesystem function for this

namespace bfs = boost::filesystem;
const bfs::path TEMP_DIR = bfs::system_complete( bfs::temp_directory_path() ); // system_complete() call is optional

• Do not place anything in ~/Documents. That is for the user to choose to organize; you should never write to a fixed path inside Documents. Your game should use ~/Library/Application Support/Your App Name/ for saves and other user data. – Kevin Reid Sep 8 '12 at 13:54
• @KevinReid "Documents that the user creates and sees in an app's user interface—for example the document browsers in Pages, Numbers, and Keynote should be stored in the Documents directory. Another example of files that might go in the Documents directory are saved games, again because they are something that an app could potentially provide some sort of method for selecting." -- Source: Apple's recommendation, in the first link. Did I miss something? – Klaim Sep 8 '12 at 22:15
• In all of those the emphasis is on selecting. The user chooses what they are named and where they go. Files which the user does not manage should not be placed in Documents, because Documents is the user's namespace, not the developer's. (Disclaimer: I do not claim that my advice is in alignment with Apple's documentation. I do claim that it reflects the majority of practice among designed-for-Mac applications and that users will be happier with it.) – Kevin Reid Sep 8 '12 at 23:11
• Also, there were no “Library” directories on pre-X Mac OS. The “(OS X)” remarks in the linked documentation are contrasting with iOS, which is a completely different question since iOS does not expose a filesystem to the user. – Kevin Reid Sep 8 '12 at 23:12
• @KevinReid I'll update the Library stuff, thanks. However for what you say about selecting and Documents, this seems contradictory. Save games are user-relative, not application or developer relative. Well it depends on the game, which is why there is also a shared game data directory. So I don't understand what you mean exactly. Is there some rational somewhere about that? – Klaim Sep 9 '12 at 8:25

# Linux Debian (Ubuntu, Fedora, etc.)

Based on:

In unix-based OS, the ~ directory is automatically located at the user's home directory where user-specific data are located. This means that whatever the language, on these platforms you can access automatically this folder by using ~ instead of using a OS-specific function. Also note that / is the root path of the whole system, not a path to the root of the main disk.

Append your own directory with game name or game company then game name to these directories.

# Player's game data

Traditionally, for the game Aquaria it would be:

~/.aquaria

Note that directories and files starting with . will be hidden by default to the user.

Most desktops now try to adhere to the XDG specification, which recommends

$XDG_CONFIG_HOME/aquaria or$XDG_DATA_HOME/aquaria

for configuration and savegames instead.

If $XDG_CONFIG_HOME not set use : ~/.config/aquaria or ~/.local/aquaria This is mostly to unclutter user's home directory, as well as allow users to run multiple profiles of an application if they deem it necessary. There are also other dedicated user-specific directories in the specification. # Shared game data /var/games/ Shared config files should be located in /etc/games/ # Temporary game data /tmp • To elaborate: a game "Aquaria" should put its game data in ~/.aquaria (or ~/.config/Aquaria). It's frowned upon to have a world-writable directory in /var; the general way of making that happen is to create a user account for your game and make it the only account that can write to that directory (and then use setuid when normal people are playing the game). This might be more work than you want. – dhasenan Sep 8 '12 at 12:21 • Well, actually, most desktops now try to adhere to the XDG specification, which recommends$XDG_CONFIG_HOME/aquaria (or ~/.config/aquaria if not set) and \$XDG_DATA_HOME/aquaria (or ~/.local/aquaria) for configuration and savegames instead (see standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). This is mostly to unclutter user's home directory, as well as allow users to run multiple profiles of an application if they deem it necessary. There are also other dedicated user-specific directories in the specification. – liori Sep 8 '12 at 18:17
• @liori I'll update the answers tomorrow if I can find time, sorry for the delay. If you feel like it and have the time, please feel free to update the info. It's useful to me too. – Klaim Sep 8 '12 at 22:17