Relative Paths...
Posted
#1
(In Topic #1363)
Regular

I'm trying to save a new file to the relative path: ../.public/myfilename.json but get the 'Access forbidden' error when debugging!
I've checked the Permissions for the .public folder and set them to: create and delete; read/write across owner,group and user,
then reloaded the project, but all to no avail. The Encode works fine, btw. Any ideas?
my code is as straight-forward as this
Code (gambas)
- fileSpec = "../.public/myfilename.json"
Thanks,
C.
Posted
Guru

use Application.Path &/ ".public/myfilename.json"
/cat/path - Gambas Documentation
Posted
Regular

Where did you expect that relative path to point to? It's not the directory above the one we are running in, it means "the component above this one" as in "the component where this was called from".
If you truly want the directory above the current run directory then modify BruceS's code to:
Code (gambas)
b
Posted
Regular

This line - "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." - under Relative Paths in the documentation /cat/path - Gambas Documentation is a bit misleading I feel. It suggested to me that 'relative paths' should therefore be used instead, and that "../" - specified in a previous statement - is the syntax to use.
The whole page could be re-written to be less ambiguous/confusing, with the 'application.path' solutions included as examples perhaps!
Regards,
C.
Posted
Guru

chrisRoald said
The whole page could be re-written to be less ambiguous/confusing, with the 'application.path' solutions included as examples perhaps!
Go for it Chris , it's a community created wiki.
If you want changes you are free to change it.
Everyone else is busy
Posted
Guru

You were right it was a bit misleading,
I believe all that part is trying to say is that you can modify files in the project with their absolute path but then when running the program as an executable, unless you have hit "Make executable" and re-made the archive, they (the modified files) do not yet exist in the archive. but when using the IDE it uses the modified files each time you hit run.
So i changed it to this, hopefully makes more sense…
wiki said
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.
If you think it should be worded differently ,,,. then word it differently
Posted
Regular

Dont write code that tries to modify files inside your project.
Seems to cover it without referring to any type of pathing.
b
Posted
Regular

The user is entering data that I want saved, field by field, to prevent data loss through power-failure or program-crash! The final location/path of their data (json files) hasn't been decided yet by the user. My plan was to save in the .public directory. Does such a 'location' exist in executableLand?
Sorry to appear dim, but terms such as 'project', 'ide' and 'archive' I'm having to try and decide precisely what they mean/imply gambasWise as I go along.
I think it's too early to be amending open documentation as I'm still on a huge learningCurve; but I'm enjoying the journey - mostly
Regards,
C.
Posted
Guru

the executable (archive, same thing) it is completely read only.
But generally you do not want to use your project folder. you are free to use it if you like, it's just bad practice as moving/renaming it will mess things up in your code paths. plus there can be other issues.
For your case I would maybe use a folder in ~/.config/ or even just simply use Setting.class
Ie.
As the user types data in the fields just save some settings…
Code (gambas)
- ' do the same for all other entry fields
Then if crash when program is run the Settings["CurrentEntry/xxx"] fields will be available to restore.
Posted
Guru

You'll soon figure it all out
Posted
Guru

You do not actually need to make a gambas executable at all and can just run the project from the folder.
There are 2 ways to run a gambas project/program..
1. As an executable.
This it's typical use. Use the IDE to "Make an executable" then you have a "projectName.gambas" file that is actually just an archive.
All the projects files (excluding ALL .hidden files and folders except .public) are added to the archive and can be accessed to read.
(for certain usages a file may not be accessible and you have to move it out of the archive to a temp folder first)
But for the most part the .gambas executable file can then be placed anywhere outside of the project dir and run from there and have all it's project files in it's internal relative paths.
./ for project root
../ for components (like gb.form) to see their own root not the projects.
2. As a project.
Just use gbx3 /path/to/project-dir
This way your actual "project" is run, not an "executable"
It is basically the same as loading the IDE and hitting "Run" but without the IDE and debugging
So you can access .hidden folders that would otherwise not be added to the executable.
Any changes to project files would not need to be re-added to any executable, it's all live.
Hope that helps
1 guest and 0 members have just viewed this.


