Local Directories

From C# Gamedev Wiki
Revision as of 21:23, 9 June 2024 by Winkio (talk | contribs) (Created page with "To get to specific local directories on the system where a game is running <syntaxhighlight lang="cs"> Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) </syntaxhighlight> This works on multiple platforms, including windows, linux, mac, and android. For example, if you wanted to create a folder under ‘My Games’ for a single game's save data, consider the following code: <syntaxhighlight lang="cs"> string gameName = "Tetris"; string userDirectory =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To get to specific local directories on the system where a game is running

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

This works on multiple platforms, including windows, linux, mac, and android.

For example, if you wanted to create a folder under ‘My Games’ for a single game's save data, consider the following code:

string gameName = "Tetris";
string userDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", gameName);
if (!Directory.Exists(userDirectory))
{
    Directory.CreateDirectory(userDirectory);
}

More information can be found at: