How to navigate through folders with python?

hi. how can i cd throug folders in the linux home directory… and save the game config file to for ex. /home/username/.game/ ?

and how can i do this in windows… and where would you recommend to save the game files in this os?

os.path.expanduser("~") should give you the user directory.

hey thank you :slight_smile: now i’m going to use it :wink:

I would recommend giving you game a folder structure such as:

|_ Game.blend
|_ /saves
  |_ save_01.txt
  |_ save_02.txt

And save all the game data in the /saves/ folder. Its not really good practice to have a program which creates files in obscure locations on a hard drive, best to keep it within that program’s own folder. Personally, I hate when programs create files/folders in my personal files directory (my documents).

You can retrieve retrieve that /saves/ folder with:

path = GameLogi.expandPath("//saves")

yes i hate it too. but in linux most of applications saves data to your home directory as files beggining with the dot like “.game” and this files is hidden or invisible… you cant see them… bcs you dont have the rights to folders like /usr or /bin or /etc and etc :smiley: only if you run it as root user… but its dangerous and you have to type password… i will create the dir /home/username/.gamename/saves/ or something like this… and in windows it will be something like "C:/Program Files/GameName/.gamename/saves/

i don’t know about windows, but for ubuntu linux i would recommend saving the gamefiles to the \home\\ folder due to several reasons:

  1. It is a usual way in linux
  2. The game is distributed as .deb packages and it is a usual way to install executable to \usr\bin\ or \usr\local\bin\ and the game data(blend files) to\usr\share\game\ folder.
    3.the game deb package is installed with root previlages and after install the user can’t edit all game data and executable except the .game folder. This way is highly recommended coz it makes your deb packages stable.
    And i don’t mind another automatically hidden .game folder in my home directory;)

yes this is what i’m doing right now - the clasical game installation in ubuntu… now i’m creating the complet python based post-installation and launcher script… hope to see my game in official ubuntu repositories :smiley:

It’s actually standard practice on Linux operating systems to save to /home/username/.program_specific_folder or in a subfolder of /home/username/.local. The extraordinary benefit to this is that it allows each user to maintain their own program specific settings and data instead of maintaining only system level settings.

Windows also has an appropriate and non-obnoxious method of doing this, though the correct directory to save user specific data to seems to change with every few releases. On XP, the correct directory is “<root>\Documents and Settings&lt;user>\Application Data&lt;program_specific_folder>” or (perhaps more correct) “<root>\Documents and Settings&lt;user>\Local Settings\Application Data&lt;program_specific_folder>”. On Windows Vista and Windows 7 user specific application data “<root>\Users&lt;user>\AppData” or “<root>\Users&lt;user>\AppData\Local”.

os.path.expanduser("~") works on Windows and Unix systems, so it should be a pretty robust solution for saving game data on most operating systems. More info here: