Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Arithmetical Functions
Arithmetic Operators
Array Declaration
Assignment Operators
Assignments
Binary Data Representation
Bits Manipulation Functions
Character Test Functions
Comparison methods
Complex numbers
Constant Declaration
Constant Expression
Conversion Functions
Datatype Functions
Datatypes
Date & Time Functions
Enumeration declaration
Error Management
Event Loop
Event Management
Events declaration
Expressions
External Function Management
File & Directory Functions
File & Directory Paths
File mode syntax
Floating Point Numbers
Formatting functions
Gambas Object Model
Global Special Event Handlers
Integer numbers
Intrinsic Functions
Language Constants
Localization and Translation Functions
Local Variable Declaration
Logarithms & Exponentials Functions
Logical Operators
Loop Control Structures
Method Declaration
Miscellaneous Control Structures
Miscellaneous Functions
Native Arrays
Native Container Classes
Object & Class Management
Operator Evaluation Order
Predefined Constants
Process Management
Property Declaration
Random Numbers Functions
Special Methods
Stream & Input/Output functions
String Functions
String Operators
Structure declaration
Test Control Structures & Functions
Trigonometric Functions
User-defined formats
Using reserved keywords as identifiers
Variable Declaration
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

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.