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.
Accessing files outside of the current project
Relative paths refers by default to the data files located in the current project executable.
To access data files located in other project executables (i.e. the main project, its libraries or components), you must use the
following special syntaxes:
../file.txt
|
Search the file in the executable calling the current one, directly or indirectly.
|
../../file.txt
|
Search the file in the executable calling the executable calling the current one, directly or indirectly.
You walk back an executable each time you add a ../ in front of the relative path.
|
.../file.txt
|
Search the file in the main project.
|
./gb.xxx/file.txt
|
Search the file in the gb.xxx component, provided it has been loaded of course.
I strongly suggest not using this syntax at the moment. It may change in the future, as it is ambiguous.
|
See also