[Gambas-user] Gambas script gbs Application.Path Args
taboege at gmail.com
Sun Nov 1 20:46:12 CET 2020
On Sun, 01 Nov 2020, Bruce Steers wrote:
> Sorry i meant the directory the script was launched from like Args and
> Application.Path would produce.
> I want to access files in the App dir like a gambas executable can.
> I used the word "working" there by mistake but thank you knowing .Dir works
> as normal is useful :)
Let me get the terminology of my answer straight: a Gambas project has a
*project directory* which is where its source code, configuration and data
files are stored. This can be accessible at runtime through Application.Path,
but keep in mind that a Gambas script is embedded into a temporary project
on the fly, so you get that project's path instead of the script file path
(as you already observed), and that Application.Path of an executable will
be something else (IIRC just /tmp). An executable is not unpacked into the
filesystem just to be able to point Application.Path to it. Therefore any
use of Application.Path in non-debugging code should raise at least two
eyebrows -- chances are you're making your project unpackageable.
Another thing is the current working directory (cwd), which is a familiar
concept from the shell and other programming languages. The cwd at program
startup is available through Application.Dir. However, the Gambas language
does *not* have a concept of "current working directory", in that relative
paths in your code are *always* interpreted by Gambas built-ins as relative
to the project directory, never to the environment's cwd. In case you're
running from an executable archive, Gambas will transparently access the
files in the memory-mapped archive structure and give you their contents.
You seem to want to use paths relative to Application.Dir. That property
should contain the right cwd no matter how you run the Gambas program --
from a project, script or executable. But maybe you're using it wrong?
I can't tell without seeing your code. Keep in mind that relative paths
in your Gambas program do *not* do what you're used to from the shell!
- Don't refer to Application.Path for project data, use relative
- Don't use relative paths for files in the cwd, make them absolute
paths with Application.Dir &/ ...
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User