How to get home directory path?
How to get home directory path?
I need it to store game's savestates, config, screenshots etc.
Or this, very similar:
But just using ~ directly in paths is probably easier...
Code: Select all
print environ("HOME")
You should also look at the library I made for configuration files: http://code.google.com/p/libfbconfig/ Direct download: http://code.google.com/p/libfbconfig/do ... fgsrc1.zip
This library could handle all configuration and even the save states easily on all supported platforms, usage example (very basic) is on the first link or you can look at the raw interface here: http://code.google.com/p/libfbconfig/so ... bconfig.bi As the primary author of this library I can answer any questions you may have if you want to use my little lib.
Also, you should use the method dkl suggested as ~ is expanded by the shell but $HOME is ALWAYS there.
This library could handle all configuration and even the save states easily on all supported platforms, usage example (very basic) is on the first link or you can look at the raw interface here: http://code.google.com/p/libfbconfig/so ... bconfig.bi As the primary author of this library I can answer any questions you may have if you want to use my little lib.
Also, you should use the method dkl suggested as ~ is expanded by the shell but $HOME is ALWAYS there.
And for data such as save games and screenshots: ~/.local/share/ApplicationNameModern distros use "~/.config/ApplicationName/" for configuration files.
And for cache files that can be regenerated automatically: ~/.cache/ApplicationName
This intends to avoid polluting the user's home dir with hordes of .ApplicationName folders. Also, it aims that deleting anything inside ~/.config is safe, it just resets the application's default settings. ~/.cache works the same for cache files.