lang • path

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 must never use absolute paths pointing at your project directory, because these paths do not exist anymore when you make an executable. You must use relative paths instead.

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 read-only.

While running your project in the IDE, project files can be modified by using absolute paths. But do not do that! As soon as your project is run as an executable, these absolute paths do not exist anymore.

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