File & Directory Paths

There are two kinds of file or directory paths in Gambas:

  • Absolute paths.

  • Relative paths.

Absolute Paths

Absolute paths start with a / or a ~ character. They are interpreted the same way as in a shell.

If a path starts with a ~ character followed by a / character, then the ~ character is replaced by the user home directory.

Otherwise, if a path starts with a ~ not followed by a /, then the characters up to the next slash or up to the path end must be a system user name. Then they are replaced by the home directory of that user.

Example

Gambas path Actual path
~/Desktop /home/benoit/Desktop
~root/Desktop /root/Desktop

You should never use absolute paths to read from your project directory, because when you make an executable these paths do not exist anymore. You should use relative paths instead to point to the files inside the executable archive.

Relative Paths

Relative paths are paths that do not start with a / character or a ~ character.

They refer to files or directories located inside the current project executable or current component executable.

Relative paths do not refer to files located in the current working directory, as there is no concept of current working directory in Gambas!

As files located inside the current project are actually archived inside one executable file, they are ALL read-only.

While running your project in the IDE, project files can be modified by using absolute paths and will be refreshed with each run. But not if your project is run as an executable. It will then be using archived files not the project folder ones, you will modify the files at their absolute path but they will not add to the application executable unless you re-make it.

When compiling an executable, .hidden files and directories (and their contents), i.e. whose names begin with a dot, are not included.

Only a hidden folder called .public is included in the executable.

So files needed by the executable must be in either a non hidden folder or in the .public folder.

If you need to access a file located in the main project from a component, it is possible! You must start your relative path with the ../ sequence.

Manipulating paths

The File class provides many static functions that allows to manipulate file paths.