How to get home directory path?

Linux specific questions.
Post Reply
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

How to get home directory path?

Post by darkhog »

I need it to store game's savestates, config, screenshots etc.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

"~" is the path to the home directory.

Modern distros use "~/.config/ApplicationName/" for configuration files.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Post by Westbeam »

Code: Select all

Shell("echo $HOME")
;-)

EDIT: Too late :(
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Post by dkl »

Or this, very similar:

Code: Select all

print environ("HOME")
But just using ~ directly in paths is probably easier...
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

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.
Aave
Posts: 128
Joined: Jun 13, 2008 19:55
Location: Helsinki, Finland

Post by Aave »

Modern distros use "~/.config/ApplicationName/" for configuration files.
And for data such as save games and screenshots: ~/.local/share/ApplicationName
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.
Post Reply